\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -6.62587008307858845004116821212687409398 \cdot 10^{87}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.897415265281475970584947986850512250588 \cdot 10^{140}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\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 r91617 = a;
double r91618 = c;
double r91619 = r91617 * r91618;
double r91620 = b;
double r91621 = d;
double r91622 = r91620 * r91621;
double r91623 = r91619 + r91622;
double r91624 = r91618 * r91618;
double r91625 = r91621 * r91621;
double r91626 = r91624 + r91625;
double r91627 = r91623 / r91626;
return r91627;
}
double f(double a, double b, double c, double d) {
double r91628 = c;
double r91629 = -6.6258700830785885e+87;
bool r91630 = r91628 <= r91629;
double r91631 = a;
double r91632 = -r91631;
double r91633 = d;
double r91634 = hypot(r91628, r91633);
double r91635 = r91632 / r91634;
double r91636 = 1.897415265281476e+140;
bool r91637 = r91628 <= r91636;
double r91638 = b;
double r91639 = r91638 * r91633;
double r91640 = fma(r91631, r91628, r91639);
double r91641 = 1.0;
double r91642 = r91641 / r91634;
double r91643 = r91640 * r91642;
double r91644 = r91643 / r91634;
double r91645 = r91631 / r91634;
double r91646 = r91637 ? r91644 : r91645;
double r91647 = r91630 ? r91635 : r91646;
return r91647;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 13.2 |
if c < -6.6258700830785885e+87Initial program 39.2
rmApplied add-sqr-sqrt39.2
Applied *-un-lft-identity39.2
Applied times-frac39.2
Simplified39.2
Simplified26.2
rmApplied associate-*r/26.2
Simplified26.1
Taylor expanded around -inf 18.0
Simplified18.0
if -6.6258700830785885e+87 < c < 1.897415265281476e+140Initial program 18.9
rmApplied add-sqr-sqrt18.9
Applied *-un-lft-identity18.9
Applied times-frac18.9
Simplified18.9
Simplified11.9
rmApplied associate-*r/11.9
Simplified11.8
rmApplied div-inv11.9
if 1.897415265281476e+140 < c Initial program 43.4
rmApplied add-sqr-sqrt43.4
Applied *-un-lft-identity43.4
Applied times-frac43.4
Simplified43.4
Simplified28.0
rmApplied associate-*r/28.0
Simplified28.0
Taylor expanded around inf 13.3
Final simplification13.2
herbie shell --seed 2019235 +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))))