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




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.5 |
|---|---|
| Target | 0.4 |
| Herbie | 24.9 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 4.20380830514134492e289Initial program 13.8
if 4.20380830514134492e289 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 62.7
rmApplied add-sqr-sqrt62.7
Applied associate-/r*62.7
Taylor expanded around 0 60.2
Final simplification24.9
herbie shell --seed 2020162
(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))))