\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -9.27892827186840393 \cdot 10^{168}:\\
\;\;\;\;\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 3.77234305398194677 \cdot 10^{-85}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 3.6837815617052844 \cdot 10^{85}:\\
\;\;\;\;\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 9.05878189337241501 \cdot 10^{204}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\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 ((double) (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) (((double) (c * c)) + ((double) (d * d))))));
}
double code(double a, double b, double c, double d) {
double VAR;
if ((c <= -9.278928271868404e+168)) {
VAR = ((double) (((double) (-1.0 * b)) / ((double) hypot(c, d))));
} else {
double VAR_1;
if ((c <= 3.772343053981947e-85)) {
VAR_1 = ((double) (((double) (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) hypot(c, d)))) / ((double) hypot(c, d))));
} else {
double VAR_2;
if ((c <= 3.6837815617052844e+85)) {
VAR_2 = ((double) (((double) (b / ((double) (((double) fma(c, c, ((double) (d * d)))) / c)))) - ((double) (a / ((double) (((double) fma(c, c, ((double) (d * d)))) / d))))));
} else {
double VAR_3;
if ((c <= 9.058781893372415e+204)) {
VAR_3 = ((double) (((double) (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) hypot(c, d)))) / ((double) hypot(c, d))));
} else {
VAR_3 = ((double) (b / ((double) hypot(c, d))));
}
VAR_2 = VAR_3;
}
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.2 |
|---|---|
| Target | 0.5 |
| Herbie | 13.1 |
if c < -9.278928271868404e+168Initial program 44.1
rmApplied add-sqr-sqrt44.1
Applied *-un-lft-identity44.1
Applied times-frac44.1
Simplified44.1
Simplified29.8
rmApplied associate-*r/29.8
Simplified29.8
Taylor expanded around -inf 13.5
if -9.278928271868404e+168 < c < 3.772343053981947e-85 or 3.6837815617052844e+85 < c < 9.058781893372415e+204Initial program 22.6
rmApplied add-sqr-sqrt22.6
Applied *-un-lft-identity22.6
Applied times-frac22.6
Simplified22.6
Simplified13.7
rmApplied associate-*r/13.6
Simplified13.5
if 3.772343053981947e-85 < c < 3.6837815617052844e+85Initial program 16.6
rmApplied div-sub16.6
Simplified14.7
Simplified12.5
if 9.058781893372415e+204 < c Initial program 41.9
rmApplied add-sqr-sqrt41.9
Applied *-un-lft-identity41.9
Applied times-frac41.9
Simplified41.9
Simplified30.8
rmApplied associate-*r/30.8
Simplified30.8
Taylor expanded around inf 11.0
Final simplification13.1
herbie shell --seed 2020120 +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))))