\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 r51751 = a;
double r51752 = c;
double r51753 = r51751 * r51752;
double r51754 = b;
double r51755 = d;
double r51756 = r51754 * r51755;
double r51757 = r51753 + r51756;
double r51758 = r51752 * r51752;
double r51759 = r51755 * r51755;
double r51760 = r51758 + r51759;
double r51761 = r51757 / r51760;
return r51761;
}
double f(double a, double b, double c, double d) {
double r51762 = a;
double r51763 = c;
double r51764 = r51762 * r51763;
double r51765 = b;
double r51766 = d;
double r51767 = r51765 * r51766;
double r51768 = r51764 + r51767;
double r51769 = r51763 * r51763;
double r51770 = r51766 * r51766;
double r51771 = r51769 + r51770;
double r51772 = r51768 / r51771;
double r51773 = 3.723435793259181e+232;
bool r51774 = r51772 <= r51773;
double r51775 = 1.0;
double r51776 = sqrt(r51771);
double r51777 = r51766 * r51765;
double r51778 = r51764 + r51777;
double r51779 = r51776 / r51778;
double r51780 = r51775 / r51779;
double r51781 = r51780 / r51776;
double r51782 = -r51762;
double r51783 = r51782 / r51776;
double r51784 = r51774 ? r51781 : r51783;
return r51784;
}




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))))