\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.984621041690948382860905188525758471732 \cdot 10^{253}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 4.040688054161811545697476400410059624914 \cdot 10^{173}:\\
\;\;\;\;\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 r5099624 = a;
double r5099625 = c;
double r5099626 = r5099624 * r5099625;
double r5099627 = b;
double r5099628 = d;
double r5099629 = r5099627 * r5099628;
double r5099630 = r5099626 + r5099629;
double r5099631 = r5099625 * r5099625;
double r5099632 = r5099628 * r5099628;
double r5099633 = r5099631 + r5099632;
double r5099634 = r5099630 / r5099633;
return r5099634;
}
double f(double a, double b, double c, double d) {
double r5099635 = c;
double r5099636 = -2.9846210416909484e+253;
bool r5099637 = r5099635 <= r5099636;
double r5099638 = a;
double r5099639 = -r5099638;
double r5099640 = d;
double r5099641 = hypot(r5099635, r5099640);
double r5099642 = r5099639 / r5099641;
double r5099643 = 4.0406880541618115e+173;
bool r5099644 = r5099635 <= r5099643;
double r5099645 = b;
double r5099646 = r5099645 * r5099640;
double r5099647 = fma(r5099638, r5099635, r5099646);
double r5099648 = r5099647 / r5099641;
double r5099649 = r5099648 / r5099641;
double r5099650 = r5099638 / r5099641;
double r5099651 = r5099644 ? r5099649 : r5099650;
double r5099652 = r5099637 ? r5099642 : r5099651;
return r5099652;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 13.4 |
if c < -2.9846210416909484e+253Initial program 40.4
rmApplied add-sqr-sqrt40.4
Applied associate-/r*40.4
rmApplied hypot-def40.4
Taylor expanded around -inf 7.9
Simplified7.9
if -2.9846210416909484e+253 < c < 4.0406880541618115e+173Initial program 22.7
rmApplied add-sqr-sqrt22.7
Applied associate-/r*22.6
rmApplied hypot-def22.6
rmApplied hypot-def14.0
rmApplied fma-def14.0
if 4.0406880541618115e+173 < c Initial program 44.0
rmApplied add-sqr-sqrt44.0
Applied associate-/r*44.0
rmApplied hypot-def44.0
Taylor expanded around inf 11.3
Final simplification13.4
herbie shell --seed 2019200 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
: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))))