\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -6.99838818051005 \cdot 10^{+73}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.938821746780901 \cdot 10^{+120}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, c, d \cdot b\right)}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r1989581 = a;
double r1989582 = c;
double r1989583 = r1989581 * r1989582;
double r1989584 = b;
double r1989585 = d;
double r1989586 = r1989584 * r1989585;
double r1989587 = r1989583 + r1989586;
double r1989588 = r1989582 * r1989582;
double r1989589 = r1989585 * r1989585;
double r1989590 = r1989588 + r1989589;
double r1989591 = r1989587 / r1989590;
return r1989591;
}
double f(double a, double b, double c, double d) {
double r1989592 = c;
double r1989593 = -6.99838818051005e+73;
bool r1989594 = r1989592 <= r1989593;
double r1989595 = a;
double r1989596 = -r1989595;
double r1989597 = d;
double r1989598 = hypot(r1989592, r1989597);
double r1989599 = r1989596 / r1989598;
double r1989600 = 1.938821746780901e+120;
bool r1989601 = r1989592 <= r1989600;
double r1989602 = 1.0;
double r1989603 = b;
double r1989604 = r1989597 * r1989603;
double r1989605 = fma(r1989595, r1989592, r1989604);
double r1989606 = r1989598 / r1989605;
double r1989607 = r1989602 / r1989606;
double r1989608 = r1989607 / r1989598;
double r1989609 = r1989595 / r1989598;
double r1989610 = r1989601 ? r1989608 : r1989609;
double r1989611 = r1989594 ? r1989599 : r1989610;
return r1989611;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.2 |
|---|---|
| Target | 0.4 |
| Herbie | 13.2 |
if c < -6.99838818051005e+73Initial program 37.1
rmApplied add-sqr-sqrt37.1
Applied associate-/r*37.0
rmApplied hypot-def37.0
Taylor expanded around -inf 17.1
Simplified17.1
if -6.99838818051005e+73 < c < 1.938821746780901e+120Initial program 18.7
rmApplied add-sqr-sqrt18.7
Applied associate-/r*18.6
rmApplied hypot-def18.6
rmApplied clear-num18.7
Simplified11.6
if 1.938821746780901e+120 < c Initial program 41.2
rmApplied add-sqr-sqrt41.2
Applied associate-/r*41.1
rmApplied hypot-def41.1
Taylor expanded around inf 14.6
Final simplification13.2
herbie shell --seed 2019153 +o rules:numerics
(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))))