\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 2.9441786499321275 \cdot 10^{+294}:\\
\;\;\;\;\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))) 2.9441786499321275e+294)
(/
(/ (- (* 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))) <= 2.9441786499321275e+294) {
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 | 25.6 |
|---|---|
| Target | 0.4 |
| Herbie | 24.8 |
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.94417864993212751e294Initial program 13.2
rmApplied add-sqr-sqrt_binary6413.3
Applied associate-/r*_binary6413.2
if 2.94417864993212751e294 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 63.4
rmApplied add-sqr-sqrt_binary6463.4
Applied associate-/r*_binary6463.4
Taylor expanded around 0 60.6
Simplified60.6
Final simplification24.8
herbie shell --seed 2020224
(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))))