\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.7042360551829521 \cdot 10^{296}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r128012 = a;
double r128013 = c;
double r128014 = r128012 * r128013;
double r128015 = b;
double r128016 = d;
double r128017 = r128015 * r128016;
double r128018 = r128014 + r128017;
double r128019 = r128013 * r128013;
double r128020 = r128016 * r128016;
double r128021 = r128019 + r128020;
double r128022 = r128018 / r128021;
return r128022;
}
double f(double a, double b, double c, double d) {
double r128023 = a;
double r128024 = c;
double r128025 = r128023 * r128024;
double r128026 = b;
double r128027 = d;
double r128028 = r128026 * r128027;
double r128029 = r128025 + r128028;
double r128030 = r128024 * r128024;
double r128031 = r128027 * r128027;
double r128032 = r128030 + r128031;
double r128033 = r128029 / r128032;
double r128034 = 3.704236055182952e+296;
bool r128035 = r128033 <= r128034;
double r128036 = sqrt(r128032);
double r128037 = r128029 / r128036;
double r128038 = r128037 / r128036;
double r128039 = -1.0;
double r128040 = r128039 * r128023;
double r128041 = r128040 / r128036;
double r128042 = r128035 ? r128038 : r128041;
return r128042;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 24.9 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.704236055182952e+296Initial program 13.8
rmApplied add-sqr-sqrt13.8
Applied associate-/r*13.7
if 3.704236055182952e+296 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.4
rmApplied add-sqr-sqrt63.4
Applied associate-/r*63.4
Taylor expanded around -inf 59.9
Final simplification24.9
herbie shell --seed 2020035
(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))))