\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 r5962949 = a;
double r5962950 = c;
double r5962951 = r5962949 * r5962950;
double r5962952 = b;
double r5962953 = d;
double r5962954 = r5962952 * r5962953;
double r5962955 = r5962951 + r5962954;
double r5962956 = r5962950 * r5962950;
double r5962957 = r5962953 * r5962953;
double r5962958 = r5962956 + r5962957;
double r5962959 = r5962955 / r5962958;
return r5962959;
}
double f(double a, double b, double c, double d) {
double r5962960 = d;
double r5962961 = 2.814854621501251e+37;
bool r5962962 = r5962960 <= r5962961;
double r5962963 = 1.0;
double r5962964 = c;
double r5962965 = r5962964 * r5962964;
double r5962966 = r5962960 * r5962960;
double r5962967 = r5962965 + r5962966;
double r5962968 = sqrt(r5962967);
double r5962969 = r5962963 / r5962968;
double r5962970 = b;
double r5962971 = r5962970 * r5962960;
double r5962972 = a;
double r5962973 = r5962964 * r5962972;
double r5962974 = r5962971 + r5962973;
double r5962975 = r5962974 / r5962968;
double r5962976 = r5962969 * r5962975;
double r5962977 = r5962970 / r5962968;
double r5962978 = r5962962 ? r5962976 : r5962977;
return r5962978;
}




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))))