\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \leq -7.275365746467164 \cdot 10^{+183}:\\
\;\;\;\;-\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \frac{\frac{\mathsf{fma}\left(c, b, -d \cdot a\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;d \leq -5.175827438536771 \cdot 10^{-73}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 2.532329616296603 \cdot 10^{-115}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\
\mathbf{elif}\;d \leq 3.4182045595690496 \cdot 10^{+70}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}\\
\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 -7.275365746467164e+183)
(- (/ a d))
(let* ((t_0 (/ (/ (fma c b (- (* d a))) (hypot d c)) (hypot d c))))
(if (<= d -5.175827438536771e-73)
t_0
(if (<= d 2.532329616296603e-115)
(- (/ b c) (/ (* d a) (* c c)))
(if (<= d 3.4182045595690496e+70)
t_0
(/ (- (/ (* c b) d) a) (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 <= -7.275365746467164e+183) {
tmp = -(a / d);
} else {
double t_0 = (fma(c, b, -(d * a)) / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (d <= -5.175827438536771e-73) {
tmp_1 = t_0;
} else if (d <= 2.532329616296603e-115) {
tmp_1 = (b / c) - ((d * a) / (c * c));
} else if (d <= 3.4182045595690496e+70) {
tmp_1 = t_0;
} else {
tmp_1 = (((c * b) / d) - a) / hypot(d, c);
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.4 |
| Herbie | 12.5 |
if d < -7.27536574646716366e183Initial program 43.8
Simplified43.8
Taylor expanded in c around 0 11.2
if -7.27536574646716366e183 < d < -5.1758274385367712e-73 or 2.5323296162966029e-115 < d < 3.4182045595690496e70Initial program 18.9
Simplified18.9
Applied add-sqr-sqrt_binary6418.9
Applied *-un-lft-identity_binary6418.9
Applied times-frac_binary6418.9
Simplified18.9
Simplified12.9
Applied associate-*l/_binary6412.8
Simplified12.8
Applied fma-neg_binary6412.8
if -5.1758274385367712e-73 < d < 2.5323296162966029e-115Initial program 21.2
Simplified21.2
Taylor expanded in c around inf 11.7
Simplified11.7
if 3.4182045595690496e70 < d Initial program 37.7
Simplified37.7
Applied add-sqr-sqrt_binary6437.7
Applied *-un-lft-identity_binary6437.7
Applied times-frac_binary6437.7
Simplified37.7
Simplified25.4
Applied associate-*l/_binary6425.3
Simplified25.3
Taylor expanded in c around 0 13.7
Final simplification12.5
herbie shell --seed 2022024
(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))))