\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \leq -2.9458923187888928 \cdot 10^{+141}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot a\\
\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 -1.757389697762391 \cdot 10^{-103}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 1.2857576694400817 \cdot 10^{-171}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\
\mathbf{elif}\;d \leq 1.096228133156405 \cdot 10^{+168}:\\
\;\;\;\;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 -2.9458923187888928e+141)
(* (/ 1.0 (hypot d c)) a)
(let* ((t_0 (/ (/ (- (* c b) (* d a)) (hypot d c)) (hypot d c))))
(if (<= d -1.757389697762391e-103)
t_0
(if (<= d 1.2857576694400817e-171)
(- (/ b c) (/ (* d a) (* c c)))
(if (<= d 1.096228133156405e+168) 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 <= -2.9458923187888928e+141) {
tmp = (1.0 / hypot(d, c)) * a;
} else {
double t_0 = (((c * b) - (d * a)) / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (d <= -1.757389697762391e-103) {
tmp_1 = t_0;
} else if (d <= 1.2857576694400817e-171) {
tmp_1 = (b / c) - ((d * a) / (c * c));
} else if (d <= 1.096228133156405e+168) {
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 | 26.8 |
|---|---|
| Target | 0.4 |
| Herbie | 12.5 |
if d < -2.9458923187888928e141Initial program 43.2
Simplified43.2
Applied add-sqr-sqrt_binary6443.2
Applied *-un-lft-identity_binary6443.2
Applied times-frac_binary6443.2
Simplified43.2
Simplified28.4
Taylor expanded in d around -inf 15.5
if -2.9458923187888928e141 < d < -1.7573896977623911e-103 or 1.28575766944008168e-171 < d < 1.09622813315640506e168Initial program 18.6
Simplified18.6
Applied add-sqr-sqrt_binary6418.6
Applied *-un-lft-identity_binary6418.6
Applied times-frac_binary6418.7
Simplified18.7
Simplified12.9
Applied associate-*l/_binary6412.7
Simplified12.7
if -1.7573896977623911e-103 < d < 1.28575766944008168e-171Initial program 24.3
Simplified24.3
Applied add-sqr-sqrt_binary6424.3
Applied *-un-lft-identity_binary6424.3
Applied times-frac_binary6424.3
Simplified24.3
Simplified13.6
Taylor expanded in d around 0 10.5
Simplified10.5
if 1.09622813315640506e168 < d Initial program 44.4
Simplified44.4
Applied add-sqr-sqrt_binary6444.4
Applied *-un-lft-identity_binary6444.4
Applied times-frac_binary6444.4
Simplified44.4
Simplified29.4
Applied associate-*l/_binary6429.4
Simplified29.4
Taylor expanded in c around 0 12.5
Simplified12.5
Final simplification12.5
herbie shell --seed 2021307
(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))))