\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -2.07444023714736019 \cdot 10^{132}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \le -8.9012661082733055 \cdot 10^{62}:\\
\;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}\\
\mathbf{elif}\;d \le 4.4076829621176479 \cdot 10^{83}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}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 VAR;
if ((d <= -2.0744402371473602e+132)) {
VAR = ((((b * c) - (a * d)) / hypot(c, d)) / hypot(c, d));
} else {
double VAR_1;
if ((d <= -8.901266108273305e+62)) {
VAR_1 = ((b / (fma(c, c, (d * d)) / c)) - (a / (fma(c, c, (d * d)) / d)));
} else {
double VAR_2;
if ((d <= 4.407682962117648e+83)) {
VAR_2 = ((((b * c) - (a * d)) / hypot(c, d)) / hypot(c, d));
} else {
VAR_2 = ((-1.0 * a) / hypot(c, d));
}
VAR_1 = VAR_2;
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.1 |
|---|---|
| Target | 0.4 |
| Herbie | 14.8 |
if d < -2.0744402371473602e+132 or -8.901266108273305e+62 < d < 4.407682962117648e+83Initial program 23.3
rmApplied add-sqr-sqrt23.4
Applied *-un-lft-identity23.4
Applied times-frac23.4
Simplified23.4
Simplified14.5
rmApplied associate-*r/14.5
Simplified14.4
if -2.0744402371473602e+132 < d < -8.901266108273305e+62Initial program 21.6
rmApplied div-sub21.6
Simplified22.4
Simplified13.6
if 4.407682962117648e+83 < d Initial program 38.6
rmApplied add-sqr-sqrt38.6
Applied *-un-lft-identity38.6
Applied times-frac38.6
Simplified38.6
Simplified26.2
rmApplied associate-*r/26.2
Simplified26.2
Taylor expanded around 0 16.6
Final simplification14.8
herbie shell --seed 2020092 +o rules:numerics
(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))))