\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -5.3927648088213951 \cdot 10^{132}:\\
\;\;\;\;\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le -1.2987370292207596 \cdot 10^{-142}:\\
\;\;\;\;\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}\;c \le 6.1765680479198497 \cdot 10^{-128}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.45382927677037052 \cdot 10^{189}:\\
\;\;\;\;\frac{\frac{c}{\frac{{\left(\sqrt{\mathsf{hypot}\left(c, d\right)}\right)}^{3}}{b}} - \frac{d}{\frac{{\left(\sqrt{\mathsf{hypot}\left(c, d\right)}\right)}^{3}}{a}}}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\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 temp;
if ((c <= -5.392764808821395e+132)) {
temp = ((-1.0 * b) / hypot(c, d));
} else {
double temp_1;
if ((c <= -1.2987370292207596e-142)) {
temp_1 = ((b / (fma(c, c, (d * d)) / c)) - (a / (fma(c, c, (d * d)) / d)));
} else {
double temp_2;
if ((c <= 6.17656804791985e-128)) {
temp_2 = ((((b * c) - (a * d)) / hypot(c, d)) / hypot(c, d));
} else {
double temp_3;
if ((c <= 1.4538292767703705e+189)) {
temp_3 = (((c / (pow(sqrt(hypot(c, d)), 3.0) / b)) - (d / (pow(sqrt(hypot(c, d)), 3.0) / a))) / sqrt(hypot(c, d)));
} else {
temp_3 = (b / hypot(c, d));
}
temp_2 = temp_3;
}
temp_1 = temp_2;
}
temp = temp_1;
}
return temp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.4 |
|---|---|
| Target | 0.5 |
| Herbie | 12.6 |
if c < -5.392764808821395e+132Initial program 44.3
rmApplied add-sqr-sqrt44.3
Applied *-un-lft-identity44.3
Applied times-frac44.3
Simplified44.3
Simplified29.0
rmApplied associate-*r/28.9
Simplified28.9
Taylor expanded around -inf 14.7
if -5.392764808821395e+132 < c < -1.2987370292207596e-142Initial program 16.4
rmApplied div-sub16.4
Simplified13.8
Simplified12.1
if -1.2987370292207596e-142 < c < 6.17656804791985e-128Initial program 22.6
rmApplied add-sqr-sqrt22.6
Applied *-un-lft-identity22.6
Applied times-frac22.6
Simplified22.6
Simplified12.4
rmApplied associate-*r/12.4
Simplified12.2
if 6.17656804791985e-128 < c < 1.4538292767703705e+189Initial program 21.0
rmApplied add-sqr-sqrt21.0
Applied *-un-lft-identity21.0
Applied times-frac21.0
Simplified21.0
Simplified13.2
rmApplied associate-*r/13.2
Simplified13.1
rmApplied add-sqr-sqrt13.3
Applied associate-/r*13.4
rmApplied div-sub13.4
Applied div-sub13.4
Simplified11.9
Simplified12.2
if 1.4538292767703705e+189 < c Initial program 44.5
rmApplied add-sqr-sqrt44.5
Applied *-un-lft-identity44.5
Applied times-frac44.5
Simplified44.5
Simplified32.0
rmApplied associate-*r/32.0
Simplified32.0
Taylor expanded around inf 12.6
Final simplification12.6
herbie shell --seed 2020056 +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))))