\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 r67426 = b;
double r67427 = c;
double r67428 = r67426 * r67427;
double r67429 = a;
double r67430 = d;
double r67431 = r67429 * r67430;
double r67432 = r67428 - r67431;
double r67433 = r67427 * r67427;
double r67434 = r67430 * r67430;
double r67435 = r67433 + r67434;
double r67436 = r67432 / r67435;
return r67436;
}
double f(double a, double b, double c, double d) {
double r67437 = c;
double r67438 = -5.0891457798304875e+131;
bool r67439 = r67437 <= r67438;
double r67440 = b;
double r67441 = -r67440;
double r67442 = d;
double r67443 = hypot(r67437, r67442);
double r67444 = r67441 / r67443;
double r67445 = 1.6082228280465774e+194;
bool r67446 = r67437 <= r67445;
double r67447 = a;
double r67448 = r67442 * r67447;
double r67449 = -r67448;
double r67450 = fma(r67440, r67437, r67449);
double r67451 = r67450 / r67443;
double r67452 = r67451 / r67443;
double r67453 = r67440 / r67443;
double r67454 = r67446 ? r67452 : r67453;
double r67455 = r67439 ? r67444 : r67454;
return r67455;
}




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 associate-*r/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 associate-*r/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 associate-*r/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))))