\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} \leq 7.002575214183938 \cdot 10^{+291}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \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}(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(if (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) 7.002575214183938e+291)
(/
(/ (- (* b c) (* a d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(/ (- b) (sqrt (+ (* c c) (* d d))))))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 tmp;
if ((((b * c) - (a * d)) / ((c * c) + (d * d))) <= 7.002575214183938e+291) {
tmp = (((b * c) - (a * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else {
tmp = -b / sqrt((c * c) + (d * d));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.7 |
|---|---|
| Target | 0.5 |
| Herbie | 25.0 |
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 7.0025752141839384e291Initial program 13.7
rmApplied add-sqr-sqrt_binary64_216513.7
Applied associate-/r*_binary64_208713.6
if 7.0025752141839384e291 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 63.1
rmApplied add-sqr-sqrt_binary64_216563.1
Applied associate-/r*_binary64_208763.1
Taylor expanded around -inf 60.5
Simplified60.5
Final simplification25.0
herbie shell --seed 2020292
(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))))