\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 1.034732446536267 \cdot 10^{50}:\\
\;\;\;\;\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{b}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r64781 = a;
double r64782 = c;
double r64783 = r64781 * r64782;
double r64784 = b;
double r64785 = d;
double r64786 = r64784 * r64785;
double r64787 = r64783 + r64786;
double r64788 = r64782 * r64782;
double r64789 = r64785 * r64785;
double r64790 = r64788 + r64789;
double r64791 = r64787 / r64790;
return r64791;
}
double f(double a, double b, double c, double d) {
double r64792 = d;
double r64793 = 1.0347324465362668e+50;
bool r64794 = r64792 <= r64793;
double r64795 = a;
double r64796 = c;
double r64797 = r64795 * r64796;
double r64798 = b;
double r64799 = r64798 * r64792;
double r64800 = r64797 + r64799;
double r64801 = r64796 * r64796;
double r64802 = r64792 * r64792;
double r64803 = r64801 + r64802;
double r64804 = sqrt(r64803);
double r64805 = r64800 / r64804;
double r64806 = r64805 / r64804;
double r64807 = r64798 / r64804;
double r64808 = r64794 ? r64806 : r64807;
return r64808;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 26.5 |
if d < 1.0347324465362668e+50Initial program 23.6
rmApplied add-sqr-sqrt23.6
Applied associate-/r*23.5
if 1.0347324465362668e+50 < d Initial program 36.0
rmApplied add-sqr-sqrt36.0
Applied associate-/r*36.0
Taylor expanded around 0 36.8
Final simplification26.5
herbie shell --seed 2019199
(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))))