\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.149100964280641300340745429976416575497 \cdot 10^{52}:\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r6692837 = a;
double r6692838 = c;
double r6692839 = r6692837 * r6692838;
double r6692840 = b;
double r6692841 = d;
double r6692842 = r6692840 * r6692841;
double r6692843 = r6692839 + r6692842;
double r6692844 = r6692838 * r6692838;
double r6692845 = r6692841 * r6692841;
double r6692846 = r6692844 + r6692845;
double r6692847 = r6692843 / r6692846;
return r6692847;
}
double f(double a, double b, double c, double d) {
double r6692848 = c;
double r6692849 = -1.1491009642806413e+52;
bool r6692850 = r6692848 <= r6692849;
double r6692851 = a;
double r6692852 = -r6692851;
double r6692853 = r6692848 * r6692848;
double r6692854 = d;
double r6692855 = r6692854 * r6692854;
double r6692856 = r6692853 + r6692855;
double r6692857 = sqrt(r6692856);
double r6692858 = r6692852 / r6692857;
double r6692859 = b;
double r6692860 = r6692859 * r6692854;
double r6692861 = r6692851 * r6692848;
double r6692862 = r6692860 + r6692861;
double r6692863 = r6692862 / r6692857;
double r6692864 = r6692863 / r6692857;
double r6692865 = r6692850 ? r6692858 : r6692864;
return r6692865;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.7 |
|---|---|
| Target | 0.4 |
| Herbie | 26.7 |
if c < -1.1491009642806413e+52Initial program 37.6
rmApplied add-sqr-sqrt37.6
Applied associate-/r*37.5
Taylor expanded around -inf 38.0
Simplified38.0
if -1.1491009642806413e+52 < c Initial program 23.6
rmApplied add-sqr-sqrt23.6
Applied associate-/r*23.5
Final simplification26.7
herbie shell --seed 2019170
(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))))