\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -8.854189588374422409856349074066788051196 \cdot 10^{171}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \le 2.946859042858365719350909171488092188425 \cdot 10^{116}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, -d, c \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r101340 = b;
double r101341 = c;
double r101342 = r101340 * r101341;
double r101343 = a;
double r101344 = d;
double r101345 = r101343 * r101344;
double r101346 = r101342 - r101345;
double r101347 = r101341 * r101341;
double r101348 = r101344 * r101344;
double r101349 = r101347 + r101348;
double r101350 = r101346 / r101349;
return r101350;
}
double f(double a, double b, double c, double d) {
double r101351 = d;
double r101352 = -8.854189588374422e+171;
bool r101353 = r101351 <= r101352;
double r101354 = a;
double r101355 = c;
double r101356 = hypot(r101355, r101351);
double r101357 = r101354 / r101356;
double r101358 = 2.9468590428583657e+116;
bool r101359 = r101351 <= r101358;
double r101360 = -r101351;
double r101361 = b;
double r101362 = r101355 * r101361;
double r101363 = fma(r101354, r101360, r101362);
double r101364 = r101363 / r101356;
double r101365 = r101364 / r101356;
double r101366 = -r101354;
double r101367 = r101366 / r101356;
double r101368 = r101359 ? r101365 : r101367;
double r101369 = r101353 ? r101357 : r101368;
return r101369;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 12.5 |
if d < -8.854189588374422e+171Initial program 44.5
rmApplied add-sqr-sqrt44.5
Applied *-un-lft-identity44.5
Applied times-frac44.5
Simplified44.5
Simplified30.6
rmApplied associate-*r/30.6
Simplified30.5
Taylor expanded around -inf 11.3
if -8.854189588374422e+171 < d < 2.9468590428583657e+116Initial program 19.6
rmApplied add-sqr-sqrt19.6
Applied *-un-lft-identity19.6
Applied times-frac19.6
Simplified19.6
Simplified12.5
rmApplied associate-*r/12.5
Simplified12.4
rmApplied clear-num12.5
rmApplied *-un-lft-identity12.5
Applied associate-/r*12.5
Simplified12.4
if 2.9468590428583657e+116 < d Initial program 39.9
rmApplied add-sqr-sqrt39.9
Applied *-un-lft-identity39.9
Applied times-frac39.9
Simplified39.9
Simplified26.5
rmApplied associate-*r/26.5
Simplified26.4
Taylor expanded around inf 14.1
Simplified14.1
Final simplification12.5
herbie shell --seed 2019208 +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))))