\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\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.124136587792355 \cdot 10^{+226}:\\
\;\;\;\;\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}\;d \leq -1.9738142544677371 \cdot 10^{-143}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -9.658402922807776 \cdot 10^{-195}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\
\mathbf{elif}\;d \leq 3.0970906241597073 \cdot 10^{+36}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (/ (- (* c b) (* d a)) (hypot d c)) (hypot d c))))
(if (<= d -5.124136587792355e+226)
(- (fma (/ c d) (/ b d) (/ (* a (* c c)) (pow d 3.0))) (/ a d))
(if (<= d -1.9738142544677371e-143)
t_0
(if (<= d -9.658402922807776e-195)
(- (/ b c) (/ (* d a) (* c c)))
(if (<= d 3.0970906241597073e+36)
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 t_0 = (((c * b) - (d * a)) / hypot(d, c)) / hypot(d, c);
double tmp;
if (d <= -5.124136587792355e+226) {
tmp = fma((c / d), (b / d), ((a * (c * c)) / pow(d, 3.0))) - (a / d);
} else if (d <= -1.9738142544677371e-143) {
tmp = t_0;
} else if (d <= -9.658402922807776e-195) {
tmp = (b / c) - ((d * a) / (c * c));
} else if (d <= 3.0970906241597073e+36) {
tmp = t_0;
} else {
tmp = (((c * b) / d) - a) / hypot(d, c);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 14.1 |
if d < -5.1241365877923551e226Initial program 41.8
Simplified41.8
Taylor expanded in c around 0 23.2
Simplified20.7
if -5.1241365877923551e226 < d < -1.9738142544677371e-143 or -9.6584029228077763e-195 < d < 3.09709062415970734e36Initial program 21.3
Simplified21.3
Applied add-sqr-sqrt_binary6421.3
Applied *-un-lft-identity_binary6421.3
Applied times-frac_binary6421.3
Simplified21.3
Simplified12.9
Applied associate-*l/_binary6412.8
Simplified12.8
Applied add-sqr-sqrt_binary6413.1
Applied associate-/r*_binary6413.1
Applied *-un-lft-identity_binary6413.1
Applied *-un-lft-identity_binary6413.1
Applied sqrt-prod_binary6413.1
Applied *-un-lft-identity_binary6413.1
Applied sqrt-prod_binary6413.1
Applied *-un-lft-identity_binary6413.1
Applied times-frac_binary6413.1
Applied times-frac_binary6413.1
Applied times-frac_binary6413.1
Simplified13.1
Simplified12.8
if -1.9738142544677371e-143 < d < -9.6584029228077763e-195Initial program 23.2
Simplified23.2
Applied add-sqr-sqrt_binary6423.2
Applied *-un-lft-identity_binary6423.2
Applied times-frac_binary6423.3
Simplified23.2
Simplified12.1
Taylor expanded in d around 0 11.7
Simplified11.7
if 3.09709062415970734e36 < d Initial program 35.1
Simplified35.1
Applied add-sqr-sqrt_binary6435.1
Applied *-un-lft-identity_binary6435.1
Applied times-frac_binary6435.1
Simplified35.1
Simplified24.4
Applied associate-*l/_binary6424.3
Simplified24.3
Taylor expanded in c around 0 16.2
Final simplification14.1
herbie shell --seed 2022125
(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))))