\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -6.168252273035428116634666578508607606907 \cdot 10^{142}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.471879606969755152618569647273648320471 \cdot 10^{167}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\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 r119550 = a;
double r119551 = c;
double r119552 = r119550 * r119551;
double r119553 = b;
double r119554 = d;
double r119555 = r119553 * r119554;
double r119556 = r119552 + r119555;
double r119557 = r119551 * r119551;
double r119558 = r119554 * r119554;
double r119559 = r119557 + r119558;
double r119560 = r119556 / r119559;
return r119560;
}
double f(double a, double b, double c, double d) {
double r119561 = c;
double r119562 = -6.168252273035428e+142;
bool r119563 = r119561 <= r119562;
double r119564 = a;
double r119565 = -r119564;
double r119566 = d;
double r119567 = hypot(r119561, r119566);
double r119568 = r119565 / r119567;
double r119569 = 1.4718796069697552e+167;
bool r119570 = r119561 <= r119569;
double r119571 = b;
double r119572 = r119571 * r119566;
double r119573 = fma(r119564, r119561, r119572);
double r119574 = r119573 / r119567;
double r119575 = r119574 / r119567;
double r119576 = r119564 / r119567;
double r119577 = r119570 ? r119575 : r119576;
double r119578 = r119563 ? r119568 : r119577;
return r119578;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.5 |
|---|---|
| Target | 0.5 |
| Herbie | 12.9 |
if c < -6.168252273035428e+142Initial program 44.8
rmApplied add-sqr-sqrt44.8
Applied *-un-lft-identity44.8
Applied times-frac44.8
Simplified44.8
Simplified29.4
rmApplied associate-*r/29.4
Simplified29.4
Taylor expanded around -inf 13.9
Simplified13.9
if -6.168252273035428e+142 < c < 1.4718796069697552e+167Initial program 19.6
rmApplied add-sqr-sqrt19.6
Applied *-un-lft-identity19.6
Applied times-frac19.6
Simplified19.6
Simplified12.8
rmApplied associate-*r/12.8
Simplified12.7
if 1.4718796069697552e+167 < c Initial program 45.4
rmApplied add-sqr-sqrt45.4
Applied *-un-lft-identity45.4
Applied times-frac45.4
Simplified45.4
Simplified29.8
rmApplied associate-*r/29.8
Simplified29.7
Taylor expanded around inf 12.5
Final simplification12.9
herbie shell --seed 2019306 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))