\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.15167370780975257 \cdot 10^{185}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 1.4191655951273249 \cdot 10^{147}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\end{array}double f(double a, double b, double c, double d) {
double r120612 = a;
double r120613 = c;
double r120614 = r120612 * r120613;
double r120615 = b;
double r120616 = d;
double r120617 = r120615 * r120616;
double r120618 = r120614 + r120617;
double r120619 = r120613 * r120613;
double r120620 = r120616 * r120616;
double r120621 = r120619 + r120620;
double r120622 = r120618 / r120621;
return r120622;
}
double f(double a, double b, double c, double d) {
double r120623 = c;
double r120624 = -2.1516737078097526e+185;
bool r120625 = r120623 <= r120624;
double r120626 = -1.0;
double r120627 = a;
double r120628 = r120626 * r120627;
double r120629 = d;
double r120630 = hypot(r120623, r120629);
double r120631 = 1.0;
double r120632 = r120630 * r120631;
double r120633 = r120628 / r120632;
double r120634 = 1.4191655951273249e+147;
bool r120635 = r120623 <= r120634;
double r120636 = r120627 * r120623;
double r120637 = b;
double r120638 = r120637 * r120629;
double r120639 = r120636 + r120638;
double r120640 = r120639 / r120630;
double r120641 = r120640 / r120632;
double r120642 = r120627 / r120632;
double r120643 = r120635 ? r120641 : r120642;
double r120644 = r120625 ? r120633 : r120643;
return r120644;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.4 |
|---|---|
| Target | 0.4 |
| Herbie | 13.2 |
if c < -2.1516737078097526e+185Initial program 43.5
rmApplied add-sqr-sqrt43.5
Applied *-un-lft-identity43.5
Applied times-frac43.5
Simplified43.5
Simplified30.2
rmApplied associate-*r/30.1
Simplified30.1
Taylor expanded around -inf 12.0
if -2.1516737078097526e+185 < c < 1.4191655951273249e+147Initial program 20.6
rmApplied add-sqr-sqrt20.6
Applied *-un-lft-identity20.6
Applied times-frac20.6
Simplified20.6
Simplified13.2
rmApplied associate-*r/13.1
Simplified13.1
rmApplied fma-udef13.1
if 1.4191655951273249e+147 < c Initial program 44.8
rmApplied add-sqr-sqrt44.8
Applied *-un-lft-identity44.8
Applied times-frac44.8
Simplified44.8
Simplified27.8
rmApplied associate-*r/27.8
Simplified27.7
Taylor expanded around inf 14.7
Final simplification13.2
herbie shell --seed 2020062 +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))))