\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -5.1227572413769072 \cdot 10^{95}:\\
\;\;\;\;\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 6.69895789485502902 \cdot 10^{-106}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{b \cdot c - a \cdot d}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 2.54946443013026016 \cdot 10^{79}:\\
\;\;\;\;\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 4.6230231189603044 \cdot 10^{141}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{b \cdot c - a \cdot d}}}{\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 <= -5.122757241376907e+95)) {
VAR = ((double) (((double) (-1.0 * b)) / ((double) hypot(c, d))));
} else {
double VAR_1;
if ((c <= 6.698957894855029e-106)) {
VAR_1 = ((double) (((double) (1.0 / ((double) (((double) hypot(c, d)) / ((double) (((double) (b * c)) - ((double) (a * d)))))))) / ((double) hypot(c, d))));
} else {
double VAR_2;
if ((c <= 2.54946443013026e+79)) {
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 <= 4.6230231189603044e+141)) {
VAR_3 = ((double) (((double) (1.0 / ((double) (((double) hypot(c, d)) / ((double) (((double) (b * c)) - ((double) (a * 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.4 |
|---|---|
| Target | 0.4 |
| Herbie | 12.9 |
if c < -5.122757241376907e+95Initial program 39.9
rmApplied add-sqr-sqrt39.9
Applied *-un-lft-identity39.9
Applied times-frac39.9
Simplified39.9
Simplified27.7
rmApplied associate-*r/27.7
Simplified27.6
Taylor expanded around -inf 15.3
if -5.122757241376907e+95 < c < 6.698957894855029e-106 or 2.54946443013026e+79 < c < 4.6230231189603044e+141Initial program 20.0
rmApplied add-sqr-sqrt20.0
Applied *-un-lft-identity20.0
Applied times-frac20.1
Simplified20.1
Simplified12.4
rmApplied associate-*r/12.3
Simplified12.3
rmApplied clear-num12.3
if 6.698957894855029e-106 < c < 2.54946443013026e+79Initial program 15.7
rmApplied div-sub15.7
Simplified14.4
Simplified11.8
if 4.6230231189603044e+141 < c Initial program 44.2
rmApplied add-sqr-sqrt44.2
Applied *-un-lft-identity44.2
Applied times-frac44.2
Simplified44.2
Simplified28.3
rmApplied associate-*r/28.2
Simplified28.2
Taylor expanded around inf 13.3
Final simplification12.9
herbie shell --seed 2020121 +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))))