\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -5.089145779830487536688267543405577993059 \cdot 10^{131}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.608222828046577445825524961558493147213 \cdot 10^{194}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, c, -d \cdot a\right)}{\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 r78944 = b;
double r78945 = c;
double r78946 = r78944 * r78945;
double r78947 = a;
double r78948 = d;
double r78949 = r78947 * r78948;
double r78950 = r78946 - r78949;
double r78951 = r78945 * r78945;
double r78952 = r78948 * r78948;
double r78953 = r78951 + r78952;
double r78954 = r78950 / r78953;
return r78954;
}
double f(double a, double b, double c, double d) {
double r78955 = c;
double r78956 = -5.0891457798304875e+131;
bool r78957 = r78955 <= r78956;
double r78958 = b;
double r78959 = -r78958;
double r78960 = d;
double r78961 = hypot(r78955, r78960);
double r78962 = r78959 / r78961;
double r78963 = 1.6082228280465774e+194;
bool r78964 = r78955 <= r78963;
double r78965 = a;
double r78966 = r78960 * r78965;
double r78967 = -r78966;
double r78968 = fma(r78958, r78955, r78967);
double r78969 = r78968 / r78961;
double r78970 = r78969 / r78961;
double r78971 = r78958 / r78961;
double r78972 = r78964 ? r78970 : r78971;
double r78973 = r78957 ? r78962 : r78972;
return r78973;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 12.6 |
if c < -5.0891457798304875e+131Initial program 42.5
rmApplied add-sqr-sqrt42.5
Applied *-un-lft-identity42.5
Applied times-frac42.5
Simplified42.5
Simplified27.7
rmApplied *-un-lft-identity27.7
Applied *-un-lft-identity27.7
Applied times-frac27.7
Applied associate-*l*27.7
Simplified27.6
Taylor expanded around -inf 13.4
Simplified13.4
if -5.0891457798304875e+131 < c < 1.6082228280465774e+194Initial program 20.4
rmApplied add-sqr-sqrt20.4
Applied *-un-lft-identity20.4
Applied times-frac20.4
Simplified20.4
Simplified12.8
rmApplied *-un-lft-identity12.8
Applied *-un-lft-identity12.8
Applied times-frac12.8
Applied associate-*l*12.8
Simplified12.7
if 1.6082228280465774e+194 < c Initial program 42.7
rmApplied add-sqr-sqrt42.7
Applied *-un-lft-identity42.7
Applied times-frac42.7
Simplified42.7
Simplified31.0
rmApplied *-un-lft-identity31.0
Applied *-un-lft-identity31.0
Applied times-frac31.0
Applied associate-*l*31.0
Simplified30.9
Taylor expanded around inf 10.7
Final simplification12.6
herbie shell --seed 2019323 +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))))