\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \leq -1.6659650814561475 \cdot 10^{+159} \lor \neg \left(d \leq 1.2030428421309446 \cdot 10^{+113}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\frac{{d}^{3}}{c}}, a, \frac{b}{d} \cdot \left(\frac{c}{d} - {\left(\frac{c}{d}\right)}^{3}\right)\right) - \frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\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 (<= d -1.6659650814561475e+159) (not (<= d 1.2030428421309446e+113)))
(-
(fma (/ c (/ (pow d 3.0) c)) a (* (/ b d) (- (/ c d) (pow (/ c d) 3.0))))
(/ a d))
(/ (/ (- (* c b) (* d a)) (hypot d c)) (hypot d c))))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 ((d <= -1.6659650814561475e+159) || !(d <= 1.2030428421309446e+113)) {
tmp = fma((c / (pow(d, 3.0) / c)), a, ((b / d) * ((c / d) - pow((c / d), 3.0)))) - (a / d);
} else {
tmp = (((c * b) - (d * a)) / hypot(d, c)) / hypot(d, c);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.1 |
|---|---|
| Target | 0.5 |
| Herbie | 11.1 |
if d < -1.6659650814561475e159 or 1.2030428421309446e113 < d Initial program 42.2
Taylor expanded in c around 0 26.3
Simplified8.3
if -1.6659650814561475e159 < d < 1.2030428421309446e113Initial program 19.3
Applied add-sqr-sqrt_binary6419.3
Applied *-un-lft-identity_binary6419.3
Applied times-frac_binary6419.3
Simplified19.3
Simplified12.4
Applied associate-*l/_binary6412.2
Simplified12.2
Final simplification11.1
herbie shell --seed 2022067
(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))))