\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.9064590122309793 \cdot 10^{+107}:\\
\;\;\;\;\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 r7501015 = a;
double r7501016 = c;
double r7501017 = r7501015 * r7501016;
double r7501018 = b;
double r7501019 = d;
double r7501020 = r7501018 * r7501019;
double r7501021 = r7501017 + r7501020;
double r7501022 = r7501016 * r7501016;
double r7501023 = r7501019 * r7501019;
double r7501024 = r7501022 + r7501023;
double r7501025 = r7501021 / r7501024;
return r7501025;
}
double f(double a, double b, double c, double d) {
double r7501026 = c;
double r7501027 = -2.9064590122309793e+107;
bool r7501028 = r7501026 <= r7501027;
double r7501029 = a;
double r7501030 = -r7501029;
double r7501031 = r7501026 * r7501026;
double r7501032 = d;
double r7501033 = r7501032 * r7501032;
double r7501034 = r7501031 + r7501033;
double r7501035 = sqrt(r7501034);
double r7501036 = r7501030 / r7501035;
double r7501037 = b;
double r7501038 = r7501037 * r7501032;
double r7501039 = r7501029 * r7501026;
double r7501040 = r7501038 + r7501039;
double r7501041 = r7501040 / r7501035;
double r7501042 = r7501041 / r7501035;
double r7501043 = r7501028 ? r7501036 : r7501042;
return r7501043;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.7 |
|---|---|
| Target | 0.5 |
| Herbie | 25.6 |
if c < -2.9064590122309793e+107Initial program 41.1
rmApplied add-sqr-sqrt41.1
Applied associate-/r*41.1
Taylor expanded around -inf 40.4
Simplified40.4
if -2.9064590122309793e+107 < c Initial program 22.6
rmApplied add-sqr-sqrt22.6
Applied associate-/r*22.5
Final simplification25.6
herbie shell --seed 2019104
(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))))