\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.80177163456015306 \cdot 10^{166}:\\
\;\;\;\;\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 15887.488683001407:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 5.72973528703112928 \cdot 10^{117}:\\
\;\;\;\;\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 3.7088384315115279 \cdot 10^{128}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\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 ((c <= -3.801771634560153e+166)) {
VAR = ((-1.0 * b) / (hypot(c, d) * 1.0));
} else {
double VAR_1;
if ((c <= 15887.488683001407)) {
VAR_1 = ((((b * c) - (a * d)) / hypot(c, d)) / (hypot(c, d) * 1.0));
} else {
double VAR_2;
if ((c <= 5.729735287031129e+117)) {
VAR_2 = ((b / (fma(c, c, (d * d)) / c)) - (a / (fma(c, c, (d * d)) / d)));
} else {
double VAR_3;
if ((c <= 3.708838431511528e+128)) {
VAR_3 = ((((b * c) - (a * d)) / hypot(c, d)) / (hypot(c, d) * 1.0));
} else {
VAR_3 = (b / (hypot(c, d) * 1.0));
}
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.1 |
|---|---|
| Target | 0.5 |
| Herbie | 12.4 |
if c < -3.801771634560153e+166Initial program 44.0
rmApplied add-sqr-sqrt44.0
Applied *-un-lft-identity44.0
Applied times-frac44.0
Simplified44.0
Simplified29.2
rmApplied associate-*l/29.2
Simplified29.2
Taylor expanded around -inf 13.3
if -3.801771634560153e+166 < c < 15887.488683001407 or 5.729735287031129e+117 < c < 3.708838431511528e+128Initial program 19.5
rmApplied add-sqr-sqrt19.5
Applied *-un-lft-identity19.5
Applied times-frac19.5
Simplified19.5
Simplified12.2
rmApplied associate-*l/12.0
Simplified12.0
if 15887.488683001407 < c < 5.729735287031129e+117Initial program 18.7
rmApplied div-sub18.7
Simplified12.9
Simplified12.1
if 3.708838431511528e+128 < c Initial program 43.0
rmApplied add-sqr-sqrt43.0
Applied *-un-lft-identity43.0
Applied times-frac43.0
Simplified43.0
Simplified29.2
rmApplied associate-*l/29.1
Simplified29.1
Taylor expanded around inf 13.6
Final simplification12.4
herbie shell --seed 2020075 +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))))