\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 1.39961108870036364 \cdot 10^{39}:\\
\;\;\;\;\frac{b}{\frac{{c}^{2} + {d}^{2}}{c}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double code(double a, double b, double c, double d) {
return ((double) (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) (((double) (c * c)) + ((double) (d * d))))));
}
double code(double a, double b, double c, double d) {
double VAR;
if ((d <= 1.3996110887003636e+39)) {
VAR = ((double) (((double) (b / ((double) (((double) (((double) pow(c, 2.0)) + ((double) pow(d, 2.0)))) / c)))) - ((double) (((double) (a * d)) / ((double) (((double) (c * c)) + ((double) (d * d))))))));
} else {
VAR = ((double) (((double) (((double) (b * c)) / ((double) (((double) (c * c)) + ((double) (d * d)))))) - ((double) (((double) (a / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))))) * ((double) (d / ((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 | 26.2 |
|---|---|
| Target | 0.5 |
| Herbie | 23.9 |
if d < 1.3996110887003636e+39Initial program 23.7
rmApplied div-sub23.7
rmApplied associate-/l*21.7
Simplified21.7
if 1.3996110887003636e+39 < d Initial program 34.8
rmApplied div-sub34.8
rmApplied add-sqr-sqrt34.8
Applied times-frac31.6
Final simplification23.9
herbie shell --seed 2020129
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))