\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \leq -5.4169787017492545 \cdot 10^{+162}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := c \cdot b - d \cdot a\\
t_1 := \frac{\frac{t_0}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;c \leq -2.1677196728423193 \cdot 10^{-219}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq 3.987912938734293 \cdot 10^{-250}:\\
\;\;\;\;\frac{c \cdot b}{{d}^{2}} - \frac{a}{d}\\
\mathbf{elif}\;c \leq 4.047882704981183 \cdot 10^{-149}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(d, c\right)}{\frac{1}{\frac{\mathsf{hypot}\left(d, c\right)}{t_0}}}}\\
\mathbf{elif}\;c \leq 2.788697051011863 \cdot 10^{-72}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{b}{d}, \frac{a \cdot \left(c \cdot c\right)}{{d}^{3}}\right) - \frac{a}{d}\\
\mathbf{elif}\;c \leq 1.3632044865862293 \cdot 10^{+39}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{\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 (<= c -5.4169787017492545e+162)
(/ (- b) (hypot d c))
(let* ((t_0 (- (* c b) (* d a))) (t_1 (/ (/ t_0 (hypot d c)) (hypot d c))))
(if (<= c -2.1677196728423193e-219)
t_1
(if (<= c 3.987912938734293e-250)
(- (/ (* c b) (pow d 2.0)) (/ a d))
(if (<= c 4.047882704981183e-149)
(/ 1.0 (/ (hypot d c) (/ 1.0 (/ (hypot d c) t_0))))
(if (<= c 2.788697051011863e-72)
(- (fma (/ c d) (/ b d) (/ (* a (* c c)) (pow d 3.0))) (/ a d))
(if (<= c 1.3632044865862293e+39)
t_1
(/ (- b (/ (* d a) 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 (c <= -5.4169787017492545e+162) {
tmp = -b / hypot(d, c);
} else {
double t_0 = (c * b) - (d * a);
double t_1 = (t_0 / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (c <= -2.1677196728423193e-219) {
tmp_1 = t_1;
} else if (c <= 3.987912938734293e-250) {
tmp_1 = ((c * b) / pow(d, 2.0)) - (a / d);
} else if (c <= 4.047882704981183e-149) {
tmp_1 = 1.0 / (hypot(d, c) / (1.0 / (hypot(d, c) / t_0)));
} else if (c <= 2.788697051011863e-72) {
tmp_1 = fma((c / d), (b / d), ((a * (c * c)) / pow(d, 3.0))) - (a / d);
} else if (c <= 1.3632044865862293e+39) {
tmp_1 = t_1;
} else {
tmp_1 = (b - ((d * a) / c)) / 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 | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 13.1 |
if c < -5.41697870174925451e162Initial program 43.5
Simplified43.5
Applied add-sqr-sqrt_binary6443.5
Applied *-un-lft-identity_binary6443.5
Applied times-frac_binary6443.5
Simplified43.5
Simplified28.7
Applied associate-*l/_binary6428.6
Simplified28.6
Taylor expanded in c around -inf 12.9
if -5.41697870174925451e162 < c < -2.16771967284231934e-219 or 2.7886970510118628e-72 < c < 1.3632044865862293e39Initial program 18.1
Simplified18.1
Applied add-sqr-sqrt_binary6418.1
Applied *-un-lft-identity_binary6418.1
Applied times-frac_binary6418.1
Simplified18.1
Simplified12.0
Applied associate-*l/_binary6411.9
Simplified11.9
Applied clear-num_binary6412.0
Applied *-un-lft-identity_binary6412.0
Applied associate-/r*_binary6412.0
Simplified11.9
if -2.16771967284231934e-219 < c < 3.98791293873429297e-250Initial program 22.7
Simplified22.7
Applied add-sqr-sqrt_binary6422.7
Applied *-un-lft-identity_binary6422.7
Applied times-frac_binary6422.7
Simplified22.7
Simplified12.6
Taylor expanded in d around inf 8.2
if 3.98791293873429297e-250 < c < 4.047882704981183e-149Initial program 23.6
Simplified23.6
Applied add-sqr-sqrt_binary6423.6
Applied *-un-lft-identity_binary6423.6
Applied times-frac_binary6423.6
Simplified23.6
Simplified11.8
Applied associate-*l/_binary6411.7
Simplified11.7
Applied clear-num_binary6411.7
Applied *-un-lft-identity_binary6411.7
Applied *-un-lft-identity_binary6411.7
Applied times-frac_binary6411.7
Applied associate-/l*_binary6412.1
if 4.047882704981183e-149 < c < 2.7886970510118628e-72Initial program 15.4
Simplified15.4
Taylor expanded in c around 0 21.1
Simplified20.4
if 1.3632044865862293e39 < c Initial program 34.8
Simplified34.8
Applied add-sqr-sqrt_binary6434.8
Applied *-un-lft-identity_binary6434.8
Applied times-frac_binary6434.8
Simplified34.8
Simplified23.9
Applied associate-*l/_binary6423.9
Simplified23.9
Taylor expanded in c around inf 16.0
Final simplification13.1
herbie shell --seed 2022101
(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))))