\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 r1889650 = a;
double r1889651 = c;
double r1889652 = r1889650 * r1889651;
double r1889653 = b;
double r1889654 = d;
double r1889655 = r1889653 * r1889654;
double r1889656 = r1889652 + r1889655;
double r1889657 = r1889651 * r1889651;
double r1889658 = r1889654 * r1889654;
double r1889659 = r1889657 + r1889658;
double r1889660 = r1889656 / r1889659;
return r1889660;
}
double f(double a, double b, double c, double d) {
double r1889661 = c;
double r1889662 = -6.99838818051005e+73;
bool r1889663 = r1889661 <= r1889662;
double r1889664 = a;
double r1889665 = -r1889664;
double r1889666 = d;
double r1889667 = hypot(r1889661, r1889666);
double r1889668 = r1889665 / r1889667;
double r1889669 = 1.938821746780901e+120;
bool r1889670 = r1889661 <= r1889669;
double r1889671 = 1.0;
double r1889672 = b;
double r1889673 = r1889666 * r1889672;
double r1889674 = fma(r1889664, r1889661, r1889673);
double r1889675 = r1889667 / r1889674;
double r1889676 = r1889671 / r1889675;
double r1889677 = r1889676 / r1889667;
double r1889678 = r1889664 / r1889667;
double r1889679 = r1889670 ? r1889677 : r1889678;
double r1889680 = r1889663 ? r1889668 : r1889679;
return r1889680;
}




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
rmApplied *-un-lft-identity37.0
Applied associate-/l*37.1
Simplified24.8
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 *-un-lft-identity18.6
Applied associate-/l*18.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
rmApplied *-un-lft-identity41.1
Applied associate-/l*41.2
Simplified26.4
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))))