\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 3.7234357932591811 \cdot 10^{232}:\\
\;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{a \cdot c + d \cdot b}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r87695 = a;
double r87696 = c;
double r87697 = r87695 * r87696;
double r87698 = b;
double r87699 = d;
double r87700 = r87698 * r87699;
double r87701 = r87697 + r87700;
double r87702 = r87696 * r87696;
double r87703 = r87699 * r87699;
double r87704 = r87702 + r87703;
double r87705 = r87701 / r87704;
return r87705;
}
double f(double a, double b, double c, double d) {
double r87706 = a;
double r87707 = c;
double r87708 = r87706 * r87707;
double r87709 = b;
double r87710 = d;
double r87711 = r87709 * r87710;
double r87712 = r87708 + r87711;
double r87713 = r87707 * r87707;
double r87714 = r87710 * r87710;
double r87715 = r87713 + r87714;
double r87716 = r87712 / r87715;
double r87717 = 3.723435793259181e+232;
bool r87718 = r87716 <= r87717;
double r87719 = 1.0;
double r87720 = sqrt(r87715);
double r87721 = r87710 * r87709;
double r87722 = r87708 + r87721;
double r87723 = r87720 / r87722;
double r87724 = r87719 / r87723;
double r87725 = r87724 / r87720;
double r87726 = -r87706;
double r87727 = r87726 / r87720;
double r87728 = r87718 ? r87725 : r87727;
return r87728;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 25.8 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.723435793259181e+232Initial program 13.9
rmApplied add-sqr-sqrt13.9
Applied associate-/r*13.8
rmApplied clear-num13.8
Simplified13.8
if 3.723435793259181e+232 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 60.0
rmApplied add-sqr-sqrt60.0
Applied associate-/r*60.0
Taylor expanded around -inf 59.9
Simplified59.9
Final simplification25.8
herbie shell --seed 2020045
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
: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))))