\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 -\infty \lor \neg \left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 8.875741042111203 \cdot 10^{+280}\right):\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\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}}\\
\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 (or (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) (- INFINITY))
(not
(<=
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
8.875741042111203e+280)))
(/ (- a) (sqrt (+ (* c c) (* d d))))
(/
(* (- (* b c) (* a d)) (/ 1.0 (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 (((((b * c) - (a * d)) / ((c * c) + (d * d))) <= -((double) INFINITY)) || !((((b * c) - (a * d)) / ((c * c) + (d * d))) <= 8.875741042111203e+280)) {
tmp = -a / sqrt((c * c) + (d * d));
} else {
tmp = (((b * c) - (a * d)) * (1.0 / 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.8 |
|---|---|
| Target | 0.4 |
| Herbie | 25.9 |
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0 or 8.8757410421112029e280 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 62.6
rmApplied add-sqr-sqrt_binary6462.6
Applied associate-/r*_binary6462.6
Taylor expanded around 0 59.4
Simplified59.4
if -inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 8.8757410421112029e280Initial program 12.3
rmApplied add-sqr-sqrt_binary6412.3
Applied associate-/r*_binary6412.2
rmApplied div-inv_binary6412.3
Final simplification25.9
herbie shell --seed 2020231
(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))))