\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 28148546215012511376658377374508777472:\\
\;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + c \cdot a}{\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 r7499820 = a;
double r7499821 = c;
double r7499822 = r7499820 * r7499821;
double r7499823 = b;
double r7499824 = d;
double r7499825 = r7499823 * r7499824;
double r7499826 = r7499822 + r7499825;
double r7499827 = r7499821 * r7499821;
double r7499828 = r7499824 * r7499824;
double r7499829 = r7499827 + r7499828;
double r7499830 = r7499826 / r7499829;
return r7499830;
}
double f(double a, double b, double c, double d) {
double r7499831 = d;
double r7499832 = 2.814854621501251e+37;
bool r7499833 = r7499831 <= r7499832;
double r7499834 = 1.0;
double r7499835 = c;
double r7499836 = r7499835 * r7499835;
double r7499837 = r7499831 * r7499831;
double r7499838 = r7499836 + r7499837;
double r7499839 = sqrt(r7499838);
double r7499840 = r7499834 / r7499839;
double r7499841 = b;
double r7499842 = r7499841 * r7499831;
double r7499843 = a;
double r7499844 = r7499835 * r7499843;
double r7499845 = r7499842 + r7499844;
double r7499846 = r7499845 / r7499839;
double r7499847 = r7499840 * r7499846;
double r7499848 = r7499841 / r7499839;
double r7499849 = r7499833 ? r7499847 : r7499848;
return r7499849;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 26.3 |
if d < 2.814854621501251e+37Initial program 22.8
rmApplied add-sqr-sqrt22.8
Applied *-un-lft-identity22.8
Applied times-frac22.8
if 2.814854621501251e+37 < d Initial program 35.3
rmApplied add-sqr-sqrt35.3
Applied associate-/r*35.3
Taylor expanded around 0 37.0
Final simplification26.3
herbie shell --seed 2019172
(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))))