\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 28148546215012511376658377374508777472:\\
\;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + c \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r5884477 = a;
double r5884478 = c;
double r5884479 = r5884477 * r5884478;
double r5884480 = b;
double r5884481 = d;
double r5884482 = r5884480 * r5884481;
double r5884483 = r5884479 + r5884482;
double r5884484 = r5884478 * r5884478;
double r5884485 = r5884481 * r5884481;
double r5884486 = r5884484 + r5884485;
double r5884487 = r5884483 / r5884486;
return r5884487;
}
double f(double a, double b, double c, double d) {
double r5884488 = d;
double r5884489 = 2.814854621501251e+37;
bool r5884490 = r5884488 <= r5884489;
double r5884491 = 1.0;
double r5884492 = c;
double r5884493 = r5884492 * r5884492;
double r5884494 = r5884488 * r5884488;
double r5884495 = r5884493 + r5884494;
double r5884496 = sqrt(r5884495);
double r5884497 = r5884491 / r5884496;
double r5884498 = b;
double r5884499 = r5884498 * r5884488;
double r5884500 = a;
double r5884501 = r5884492 * r5884500;
double r5884502 = r5884499 + r5884501;
double r5884503 = r5884502 / r5884496;
double r5884504 = r5884497 * r5884503;
double r5884505 = r5884498 / r5884496;
double r5884506 = r5884490 ? r5884504 : r5884505;
return r5884506;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 26.3 |
if d < 2.814854621501251e+37Initial program 22.8
rmApplied add-sqr-sqrt22.8
Applied *-un-lft-identity22.8
Applied times-frac22.8
if 2.814854621501251e+37 < d Initial program 35.3
rmApplied add-sqr-sqrt35.3
Applied associate-/r*35.3
Taylor expanded around 0 37.0
Final simplification26.3
herbie shell --seed 2019172
(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))))