\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -4.468015220407937198664692125642397129235 \cdot 10^{144}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 3.367831838990333489069970368031606022092 \cdot 10^{157}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(b, c, -d \cdot a\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 r70385 = b;
double r70386 = c;
double r70387 = r70385 * r70386;
double r70388 = a;
double r70389 = d;
double r70390 = r70388 * r70389;
double r70391 = r70387 - r70390;
double r70392 = r70386 * r70386;
double r70393 = r70389 * r70389;
double r70394 = r70392 + r70393;
double r70395 = r70391 / r70394;
return r70395;
}
double f(double a, double b, double c, double d) {
double r70396 = c;
double r70397 = -4.468015220407937e+144;
bool r70398 = r70396 <= r70397;
double r70399 = b;
double r70400 = -r70399;
double r70401 = d;
double r70402 = hypot(r70396, r70401);
double r70403 = r70400 / r70402;
double r70404 = 3.3678318389903335e+157;
bool r70405 = r70396 <= r70404;
double r70406 = 1.0;
double r70407 = a;
double r70408 = r70401 * r70407;
double r70409 = -r70408;
double r70410 = fma(r70399, r70396, r70409);
double r70411 = r70402 / r70410;
double r70412 = r70406 / r70411;
double r70413 = r70412 / r70402;
double r70414 = r70399 / r70402;
double r70415 = r70405 ? r70413 : r70414;
double r70416 = r70398 ? r70403 : r70415;
return r70416;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 12.6 |
if c < -4.468015220407937e+144Initial program 43.1
rmApplied add-sqr-sqrt43.1
Applied *-un-lft-identity43.1
Applied times-frac43.1
Simplified43.1
Simplified27.5
rmApplied *-un-lft-identity27.5
Applied associate-*l*27.5
Simplified27.4
Taylor expanded around -inf 13.9
Simplified13.9
if -4.468015220407937e+144 < c < 3.3678318389903335e+157Initial program 19.2
rmApplied add-sqr-sqrt19.2
Applied *-un-lft-identity19.2
Applied times-frac19.2
Simplified19.2
Simplified12.4
rmApplied *-un-lft-identity12.4
Applied associate-*l*12.4
Simplified12.3
rmApplied clear-num12.4
if 3.3678318389903335e+157 < c Initial program 45.3
rmApplied add-sqr-sqrt45.3
Applied *-un-lft-identity45.3
Applied times-frac45.3
Simplified45.3
Simplified29.1
rmApplied *-un-lft-identity29.1
Applied associate-*l*29.1
Simplified29.1
Taylor expanded around inf 12.8
Final simplification12.6
herbie shell --seed 2019326 +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))))