\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.284532853290371 \cdot 10^{+137}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.1770311826568578 \cdot 10^{+166}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r3143608 = a;
double r3143609 = c;
double r3143610 = r3143608 * r3143609;
double r3143611 = b;
double r3143612 = d;
double r3143613 = r3143611 * r3143612;
double r3143614 = r3143610 + r3143613;
double r3143615 = r3143609 * r3143609;
double r3143616 = r3143612 * r3143612;
double r3143617 = r3143615 + r3143616;
double r3143618 = r3143614 / r3143617;
return r3143618;
}
double f(double a, double b, double c, double d) {
double r3143619 = c;
double r3143620 = -1.284532853290371e+137;
bool r3143621 = r3143619 <= r3143620;
double r3143622 = a;
double r3143623 = -r3143622;
double r3143624 = d;
double r3143625 = hypot(r3143624, r3143619);
double r3143626 = r3143623 / r3143625;
double r3143627 = 1.1770311826568578e+166;
bool r3143628 = r3143619 <= r3143627;
double r3143629 = b;
double r3143630 = r3143629 * r3143624;
double r3143631 = fma(r3143622, r3143619, r3143630);
double r3143632 = 1.0;
double r3143633 = r3143632 / r3143625;
double r3143634 = r3143631 * r3143633;
double r3143635 = r3143634 / r3143625;
double r3143636 = r3143622 / r3143625;
double r3143637 = r3143628 ? r3143635 : r3143636;
double r3143638 = r3143621 ? r3143626 : r3143637;
return r3143638;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.2 |
|---|---|
| Target | 0.5 |
| Herbie | 12.9 |
if c < -1.284532853290371e+137Initial program 42.9
Simplified42.9
rmApplied add-sqr-sqrt42.9
Applied associate-/r*42.9
rmApplied fma-udef42.9
Applied hypot-def42.9
Taylor expanded around -inf 13.6
Simplified13.6
if -1.284532853290371e+137 < c < 1.1770311826568578e+166Initial program 19.9
Simplified19.9
rmApplied add-sqr-sqrt19.9
Applied associate-/r*19.8
rmApplied fma-udef19.8
Applied hypot-def19.8
rmApplied clear-num19.9
Simplified12.6
rmApplied div-inv12.9
Applied add-cube-cbrt12.9
Applied times-frac12.9
Simplified12.9
Simplified12.6
if 1.1770311826568578e+166 < c Initial program 43.3
Simplified43.3
rmApplied add-sqr-sqrt43.3
Applied associate-/r*43.3
rmApplied fma-udef43.3
Applied hypot-def43.3
rmApplied clear-num43.3
Simplified30.0
Taylor expanded around 0 13.5
Final simplification12.9
herbie shell --seed 2019141 +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))))