\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \leq -4.331249049106995 \cdot 10^{+81}:\\
\;\;\;\;\frac{a - \frac{c \cdot b}{d}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \frac{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;d \leq -5.787984791490119 \cdot 10^{-300}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 8.114742458283298 \cdot 10^{-103}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\
\mathbf{elif}\;d \leq 2.8401337548471847 \cdot 10^{+128}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-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 -4.331249049106995e+81)
(/ (- a (/ (* c b) d)) (hypot d c))
(let* ((t_0 (/ (/ (- (* c b) (* d a)) (hypot d c)) (hypot d c))))
(if (<= d -5.787984791490119e-300)
t_0
(if (<= d 8.114742458283298e-103)
(- (/ b c) (/ (* d a) (* c c)))
(if (<= d 2.8401337548471847e+128) t_0 (/ (- 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 <= -4.331249049106995e+81) {
tmp = (a - ((c * b) / d)) / hypot(d, c);
} else {
double t_0 = (((c * b) - (d * a)) / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (d <= -5.787984791490119e-300) {
tmp_1 = t_0;
} else if (d <= 8.114742458283298e-103) {
tmp_1 = (b / c) - ((d * a) / (c * c));
} else if (d <= 2.8401337548471847e+128) {
tmp_1 = t_0;
} else {
tmp_1 = -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
Results
| Original | 24.8 |
|---|---|
| Target | 0.5 |
| Herbie | 12.1 |
if d < -4.3312490491069954e81Initial program 38.2
Simplified38.2
Applied add-sqr-sqrt_binary6438.2
Applied *-un-lft-identity_binary6438.2
Applied times-frac_binary6438.2
Simplified38.2
Simplified25.3
Applied associate-*l/_binary6425.2
Simplified25.2
Taylor expanded in d around -inf 12.3
if -4.3312490491069954e81 < d < -5.7879847914901187e-300 or 8.11474245828329776e-103 < d < 2.8401337548471847e128Initial program 16.3
Simplified16.3
Applied add-sqr-sqrt_binary6416.3
Applied *-un-lft-identity_binary6416.3
Applied times-frac_binary6416.3
Simplified16.3
Simplified10.6
Applied associate-*l/_binary6410.5
Simplified10.5
if -5.7879847914901187e-300 < d < 8.11474245828329776e-103Initial program 18.9
Simplified18.9
Applied add-sqr-sqrt_binary6418.9
Applied *-un-lft-identity_binary6418.9
Applied times-frac_binary6418.9
Simplified18.9
Simplified10.2
Taylor expanded in d around 0 13.1
Simplified13.1
if 2.8401337548471847e128 < d Initial program 43.4
Simplified43.4
Applied add-sqr-sqrt_binary6443.4
Applied *-un-lft-identity_binary6443.4
Applied times-frac_binary6443.4
Simplified43.4
Simplified28.3
Applied associate-*l/_binary6428.3
Simplified28.3
Taylor expanded in c around 0 15.8
Final simplification12.1
herbie shell --seed 2022088
(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))))