\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 r120216 = b;
double r120217 = c;
double r120218 = r120216 * r120217;
double r120219 = a;
double r120220 = d;
double r120221 = r120219 * r120220;
double r120222 = r120218 - r120221;
double r120223 = r120217 * r120217;
double r120224 = r120220 * r120220;
double r120225 = r120223 + r120224;
double r120226 = r120222 / r120225;
return r120226;
}
double f(double a, double b, double c, double d) {
double r120227 = c;
double r120228 = -5.0891457798304875e+131;
bool r120229 = r120227 <= r120228;
double r120230 = b;
double r120231 = -r120230;
double r120232 = d;
double r120233 = hypot(r120227, r120232);
double r120234 = r120231 / r120233;
double r120235 = 1.6082228280465774e+194;
bool r120236 = r120227 <= r120235;
double r120237 = a;
double r120238 = r120232 * r120237;
double r120239 = -r120238;
double r120240 = fma(r120230, r120227, r120239);
double r120241 = r120240 / r120233;
double r120242 = r120241 / r120233;
double r120243 = r120230 / r120233;
double r120244 = r120236 ? r120242 : r120243;
double r120245 = r120229 ? r120234 : r120244;
return r120245;
}




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 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 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 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))))