\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.1140340824639586 \cdot 10^{240}:\\
\;\;\;\;\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 9.40027463443809988 \cdot 10^{-182}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 3.2403938167049658 \cdot 10^{148}:\\
\;\;\;\;\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 1.825216235226745 \cdot 10^{166}:\\
\;\;\;\;\frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\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 (((b * c) - (a * d)) / ((c * c) + (d * d)));
}
double code(double a, double b, double c, double d) {
double VAR;
if ((c <= -2.1140340824639586e+240)) {
VAR = ((-1.0 * b) / hypot(c, d));
} else {
double VAR_1;
if ((c <= 9.4002746344381e-182)) {
VAR_1 = ((1.0 / (hypot(c, d) * 1.0)) * (((b * c) - (a * d)) / hypot(c, d)));
} else {
double VAR_2;
if ((c <= 3.240393816704966e+148)) {
VAR_2 = ((b / (fma(c, c, (d * d)) / c)) - (a / (fma(c, c, (d * d)) / d)));
} else {
double VAR_3;
if ((c <= 1.8252162352267452e+166)) {
VAR_3 = ((((b * c) - (a * d)) * (1.0 / hypot(c, d))) / hypot(c, d));
} else {
VAR_3 = (b / 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.7 |
if c < -2.1140340824639586e+240Initial program 41.9
rmApplied add-sqr-sqrt41.9
Applied *-un-lft-identity41.9
Applied times-frac41.9
Simplified41.9
Simplified34.8
rmApplied associate-*r/34.8
Simplified34.8
Taylor expanded around -inf 9.3
if -2.1140340824639586e+240 < c < 9.4002746344381e-182Initial program 24.1
rmApplied add-sqr-sqrt24.1
Applied *-un-lft-identity24.1
Applied times-frac24.1
Simplified24.1
Simplified13.9
if 9.4002746344381e-182 < c < 3.240393816704966e+148Initial program 17.5
rmApplied div-sub17.5
Simplified15.2
Simplified13.9
if 3.240393816704966e+148 < c < 1.8252162352267452e+166Initial program 47.9
rmApplied add-sqr-sqrt47.9
Applied *-un-lft-identity47.9
Applied times-frac47.9
Simplified47.9
Simplified25.7
rmApplied associate-*r/25.8
Simplified25.7
rmApplied div-inv25.8
if 1.8252162352267452e+166 < c Initial program 44.1
rmApplied add-sqr-sqrt44.1
Applied *-un-lft-identity44.1
Applied times-frac44.1
Simplified44.1
Simplified29.5
rmApplied associate-*r/29.5
Simplified29.4
Taylor expanded around inf 13.0
Final simplification13.7
herbie shell --seed 2020103 +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))))