\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -\infty:\\
\;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 6.99199709053851744 \cdot 10^{298}:\\
\;\;\;\;\frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\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 (((b * c) - (a * d)) / ((c * c) + (d * d)));
}
double code(double a, double b, double c, double d) {
double VAR;
if (((((b * c) - (a * d)) / ((c * c) + (d * d))) <= -inf.0)) {
VAR = ((-1.0 * a) / sqrt(((c * c) + (d * d))));
} else {
double VAR_1;
if (((((b * c) - (a * d)) / ((c * c) + (d * d))) <= 6.991997090538517e+298)) {
VAR_1 = ((((b * c) - (a * d)) * (1.0 / sqrt(((c * c) + (d * d))))) / sqrt(((c * c) + (d * d))));
} else {
VAR_1 = (b / sqrt(((c * c) + (d * d))));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.1 |
|---|---|
| Target | 0.4 |
| Herbie | 24.9 |
if (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < -inf.0Initial program 64.0
rmApplied add-sqr-sqrt64.0
Applied associate-/r*64.0
Taylor expanded around 0 52.4
if -inf.0 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < 6.991997090538517e+298Initial program 11.6
rmApplied add-sqr-sqrt11.6
Applied associate-/r*11.5
rmApplied div-inv11.6
if 6.991997090538517e+298 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) Initial program 63.4
rmApplied add-sqr-sqrt63.4
Applied associate-/r*63.4
Taylor expanded around inf 60.1
Final simplification24.9
herbie shell --seed 2020102
(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))))