\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 3.9280894087478495 \cdot 10^{46}:\\
\;\;\;\;\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 code(double a, double b, double c, double d) {
return (((a * c) + (b * d)) / ((c * c) + (d * d)));
}
double code(double a, double b, double c, double d) {
double temp;
if ((d <= 3.9280894087478495e+46)) {
temp = ((((a * c) + (b * d)) / sqrt(((c * c) + (d * d)))) / sqrt(((c * c) + (d * d))));
} else {
temp = (b / sqrt(((c * c) + (d * d))));
}
return temp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 26.0 |
if d < 3.9280894087478495e+46Initial program 23.3
rmApplied add-sqr-sqrt23.3
Applied associate-/r*23.2
if 3.9280894087478495e+46 < d Initial program 35.1
rmApplied add-sqr-sqrt35.1
Applied associate-/r*35.1
Taylor expanded around 0 36.0
Final simplification26.0
herbie shell --seed 2020053
(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))))