\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} = -\infty:\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r2441424 = a;
double r2441425 = c;
double r2441426 = r2441424 * r2441425;
double r2441427 = b;
double r2441428 = d;
double r2441429 = r2441427 * r2441428;
double r2441430 = r2441426 + r2441429;
double r2441431 = r2441425 * r2441425;
double r2441432 = r2441428 * r2441428;
double r2441433 = r2441431 + r2441432;
double r2441434 = r2441430 / r2441433;
return r2441434;
}
double f(double a, double b, double c, double d) {
double r2441435 = b;
double r2441436 = d;
double r2441437 = r2441435 * r2441436;
double r2441438 = a;
double r2441439 = c;
double r2441440 = r2441438 * r2441439;
double r2441441 = r2441437 + r2441440;
double r2441442 = r2441439 * r2441439;
double r2441443 = r2441436 * r2441436;
double r2441444 = r2441442 + r2441443;
double r2441445 = r2441441 / r2441444;
double r2441446 = -inf.0;
bool r2441447 = r2441445 <= r2441446;
double r2441448 = -r2441438;
double r2441449 = sqrt(r2441444);
double r2441450 = r2441448 / r2441449;
double r2441451 = r2441441 / r2441449;
double r2441452 = r2441451 / r2441449;
double r2441453 = r2441447 ? r2441450 : r2441452;
return r2441453;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.2 |
|---|---|
| Target | 0.4 |
| Herbie | 25.7 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < -inf.0Initial program 60.5
rmApplied add-sqr-sqrt60.5
Applied associate-/r*60.5
Taylor expanded around -inf 49.4
Simplified49.4
if -inf.0 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 24.8
rmApplied add-sqr-sqrt24.8
Applied associate-/r*24.8
Final simplification25.7
herbie shell --seed 2019153
(FPCore (a b c d)
:name "Complex division, real part"
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))