\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \leq -2.531747356501993 \cdot 10^{+130}:\\
\;\;\;\;\frac{-b}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b}{\sqrt{c \cdot c + d \cdot d}} - \frac{d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\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 (<= c -2.531747356501993e+130)
(/ (- b) (sqrt (+ (* c c) (* d d))))
(/
(-
(/ (* c b) (sqrt (+ (* c c) (* d d))))
(/ (* d a) (sqrt (+ (* c c) (* d d)))))
(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 (c <= -2.531747356501993e+130) {
tmp = -b / sqrt((c * c) + (d * d));
} else {
tmp = (((c * b) / sqrt((c * c) + (d * d))) - ((d * a) / sqrt((c * c) + (d * d)))) / 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.5 |
|---|---|
| Target | 0.5 |
| Herbie | 26.2 |
if c < -2.53174735650199306e130Initial program 43.5
rmApplied add-sqr-sqrt_binary64_316943.5
Applied associate-/r*_binary64_309143.5
Taylor expanded around -inf 42.0
Simplified42.0
if -2.53174735650199306e130 < c Initial program 23.6
rmApplied add-sqr-sqrt_binary64_316923.6
Applied associate-/r*_binary64_309123.5
rmApplied div-sub_binary64_315223.5
Simplified23.5
Simplified23.5
Final simplification26.2
herbie shell --seed 2020346
(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))))