\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq 5.1795073910038136 \cdot 10^{+123}:\\
\;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\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 (<= d 5.1795073910038136e+123)
(/
(* (- (* b c) (* d a)) (/ 1.0 (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 (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) (((double) (c * c)) + ((double) (d * d)))));
}
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= 5.1795073910038136e+123)) {
tmp = (((double) (((double) (((double) (b * c)) - ((double) (d * a)))) * (1.0 / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))))) / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))));
} else {
tmp = (((double) -(a)) / ((double) sqrt(((double) (((double) (c * c)) + ((double) (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.4 |
| Herbie | 26.2 |
if d < 5.17950739100381364e123Initial program 23.3
rmApplied add-sqr-sqrt_binary6423.3
Applied associate-/r*_binary6423.2
rmApplied div-inv_binary6423.3
if 5.17950739100381364e123 < d Initial program 42.2
rmApplied add-sqr-sqrt_binary6442.2
Applied associate-/r*_binary6442.2
Taylor expanded around 0 40.6
Simplified40.6
Final simplification26.2
herbie shell --seed 2020205
(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))))