\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 1.3702276390633895 \cdot 10^{+292}:\\
\;\;\;\;\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{-a}{\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))) 1.3702276390633895e+292)
(/
(/ (- (* b c) (* a d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(/ (- a) (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))) <= 1.3702276390633895e+292) {
tmp = (((b * c) - (a * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else {
tmp = -a / 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 | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 25.2 |
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.3702276390633895e292Initial program 13.7
rmApplied add-sqr-sqrt_binary6413.7
Applied associate-/r*_binary6413.6
if 1.3702276390633895e292 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 63.5
rmApplied add-sqr-sqrt_binary6463.5
Applied associate-/r*_binary6463.5
Taylor expanded around 0 60.2
Simplified60.2
Final simplification25.2
herbie shell --seed 2020233
(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))))