\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -7.72381449609585197339080432829350912947 \cdot 10^{66}:\\
\;\;\;\;\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 3.210000869555314649690325264102980299442 \cdot 10^{117}:\\
\;\;\;\;\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 f(double a, double b, double c, double d) {
double r94079 = b;
double r94080 = c;
double r94081 = r94079 * r94080;
double r94082 = a;
double r94083 = d;
double r94084 = r94082 * r94083;
double r94085 = r94081 - r94084;
double r94086 = r94080 * r94080;
double r94087 = r94083 * r94083;
double r94088 = r94086 + r94087;
double r94089 = r94085 / r94088;
return r94089;
}
double f(double a, double b, double c, double d) {
double r94090 = c;
double r94091 = -7.723814496095852e+66;
bool r94092 = r94090 <= r94091;
double r94093 = -1.0;
double r94094 = b;
double r94095 = r94093 * r94094;
double r94096 = d;
double r94097 = hypot(r94090, r94096);
double r94098 = r94095 / r94097;
double r94099 = 3.2100008695553146e+117;
bool r94100 = r94090 <= r94099;
double r94101 = r94094 * r94090;
double r94102 = a;
double r94103 = r94102 * r94096;
double r94104 = r94101 - r94103;
double r94105 = r94104 / r94097;
double r94106 = r94105 / r94097;
double r94107 = r94094 / r94097;
double r94108 = r94100 ? r94106 : r94107;
double r94109 = r94092 ? r94098 : r94108;
return r94109;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.5 |
|---|---|
| Target | 0.5 |
| Herbie | 13.9 |
if c < -7.723814496095852e+66Initial program 37.2
rmApplied add-sqr-sqrt37.2
Applied *-un-lft-identity37.2
Applied times-frac37.2
Simplified37.2
Simplified25.4
rmApplied associate-*r/25.4
Simplified25.4
Taylor expanded around -inf 18.0
if -7.723814496095852e+66 < c < 3.2100008695553146e+117Initial program 19.3
rmApplied add-sqr-sqrt19.3
Applied *-un-lft-identity19.3
Applied times-frac19.3
Simplified19.3
Simplified12.3
rmApplied associate-*r/12.3
Simplified12.2
if 3.2100008695553146e+117 < c Initial program 40.3
rmApplied add-sqr-sqrt40.3
Applied *-un-lft-identity40.3
Applied times-frac40.3
Simplified40.3
Simplified26.0
rmApplied associate-*r/26.0
Simplified26.0
Taylor expanded around inf 15.6
Final simplification13.9
herbie shell --seed 2019353 +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))))