\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.318211213550137477706442015578382060034 \cdot 10^{283}:\\
\;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{a \cdot c + b \cdot d}}}{\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 r77903 = a;
double r77904 = c;
double r77905 = r77903 * r77904;
double r77906 = b;
double r77907 = d;
double r77908 = r77906 * r77907;
double r77909 = r77905 + r77908;
double r77910 = r77904 * r77904;
double r77911 = r77907 * r77907;
double r77912 = r77910 + r77911;
double r77913 = r77909 / r77912;
return r77913;
}
double f(double a, double b, double c, double d) {
double r77914 = a;
double r77915 = c;
double r77916 = r77914 * r77915;
double r77917 = b;
double r77918 = d;
double r77919 = r77917 * r77918;
double r77920 = r77916 + r77919;
double r77921 = r77915 * r77915;
double r77922 = r77918 * r77918;
double r77923 = r77921 + r77922;
double r77924 = r77920 / r77923;
double r77925 = 3.3182112135501375e+283;
bool r77926 = r77924 <= r77925;
double r77927 = 1.0;
double r77928 = sqrt(r77923);
double r77929 = r77928 / r77920;
double r77930 = r77927 / r77929;
double r77931 = r77930 / r77928;
double r77932 = -r77914;
double r77933 = r77932 / r77928;
double r77934 = r77926 ? r77931 : r77933;
return r77934;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 25.8 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.3182112135501375e+283Initial program 14.3
rmApplied add-sqr-sqrt14.3
Applied associate-/r*14.3
rmApplied clear-num14.3
if 3.3182112135501375e+283 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 62.6
rmApplied add-sqr-sqrt62.6
Applied associate-/r*62.6
Taylor expanded around -inf 60.3
Simplified60.3
Final simplification25.8
herbie shell --seed 2019322
(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))))