\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \leq -4.988426382296112 \cdot 10^{+108}:\\
\;\;\;\;\frac{a - \frac{c \cdot b}{d}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \frac{\frac{\mathsf{fma}\left(c, b, d \cdot \left(-a\right)\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;d \leq -1.851745546982872 \cdot 10^{-226}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 1.2315960820976547 \cdot 10^{-167}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;d \leq 2.5261196808138677 \cdot 10^{+149}:\\
\;\;\;\;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.988426382296112e+108)
(/ (- a (/ (* c b) d)) (hypot d c))
(let* ((t_0 (/ (/ (fma c b (* d (- a))) (hypot d c)) (hypot d c))))
(if (<= d -1.851745546982872e-226)
t_0
(if (<= d 1.2315960820976547e-167)
(/ b c)
(if (<= d 2.5261196808138677e+149) 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.988426382296112e+108) {
tmp = (a - ((c * b) / d)) / hypot(d, c);
} else {
double t_0 = (fma(c, b, (d * -a)) / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (d <= -1.851745546982872e-226) {
tmp_1 = t_0;
} else if (d <= 1.2315960820976547e-167) {
tmp_1 = b / c;
} else if (d <= 2.5261196808138677e+149) {
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
| Original | 26.2 |
|---|---|
| Target | 0.5 |
| Herbie | 12.1 |
if d < -4.98842638229611199e108Initial program 40.0
Simplified40.0
Applied add-sqr-sqrt_binary6440.0
Applied *-un-lft-identity_binary6440.0
Applied times-frac_binary6440.0
Simplified40.0
Simplified26.5
Applied associate-*l/_binary6426.4
Simplified26.4
Taylor expanded in d around -inf 12.7
if -4.98842638229611199e108 < d < -1.8517455469828719e-226 or 1.2315960820976547e-167 < d < 2.5261196808138677e149Initial program 17.1
Simplified17.1
Applied add-sqr-sqrt_binary6417.1
Applied *-un-lft-identity_binary6417.1
Applied times-frac_binary6417.1
Simplified17.1
Simplified11.8
Applied associate-*l/_binary6411.6
Simplified11.6
Applied fma-neg_binary6411.6
Simplified11.6
if -1.8517455469828719e-226 < d < 1.2315960820976547e-167Initial program 24.7
Simplified24.7
Taylor expanded in c around inf 11.6
if 2.5261196808138677e149 < d Initial program 45.3
Simplified45.3
Applied add-sqr-sqrt_binary6445.3
Applied *-un-lft-identity_binary6445.3
Applied times-frac_binary6445.3
Simplified45.3
Simplified30.4
Applied associate-*l/_binary6430.4
Simplified30.4
Taylor expanded in c around 0 13.7
Final simplification12.1
herbie shell --seed 2021275
(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))))