\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.4568057680652865 \cdot 10^{+145}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 4.1067418235703216 \cdot 10^{+95}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, \left(d \cdot b\right)\right)}{\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 r2927560 = a;
double r2927561 = c;
double r2927562 = r2927560 * r2927561;
double r2927563 = b;
double r2927564 = d;
double r2927565 = r2927563 * r2927564;
double r2927566 = r2927562 + r2927565;
double r2927567 = r2927561 * r2927561;
double r2927568 = r2927564 * r2927564;
double r2927569 = r2927567 + r2927568;
double r2927570 = r2927566 / r2927569;
return r2927570;
}
double f(double a, double b, double c, double d) {
double r2927571 = c;
double r2927572 = -3.4568057680652865e+145;
bool r2927573 = r2927571 <= r2927572;
double r2927574 = a;
double r2927575 = -r2927574;
double r2927576 = d;
double r2927577 = hypot(r2927576, r2927571);
double r2927578 = r2927575 / r2927577;
double r2927579 = 4.1067418235703216e+95;
bool r2927580 = r2927571 <= r2927579;
double r2927581 = b;
double r2927582 = r2927576 * r2927581;
double r2927583 = fma(r2927574, r2927571, r2927582);
double r2927584 = r2927583 / r2927577;
double r2927585 = r2927584 / r2927577;
double r2927586 = r2927574 / r2927577;
double r2927587 = r2927580 ? r2927585 : r2927586;
double r2927588 = r2927573 ? r2927578 : r2927587;
return r2927588;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 13.0 |
if c < -3.4568057680652865e+145Initial program 43.5
Simplified43.5
rmApplied add-sqr-sqrt43.5
Applied associate-/r*43.5
rmApplied fma-udef43.5
Applied hypot-def43.5
rmApplied fma-udef43.5
Applied hypot-def28.2
Taylor expanded around -inf 14.0
Simplified14.0
if -3.4568057680652865e+145 < c < 4.1067418235703216e+95Initial program 18.7
Simplified18.7
rmApplied add-sqr-sqrt18.7
Applied associate-/r*18.6
rmApplied fma-udef18.6
Applied hypot-def18.6
rmApplied fma-udef18.6
Applied hypot-def11.9
if 4.1067418235703216e+95 < c Initial program 39.0
Simplified39.0
rmApplied add-sqr-sqrt39.0
Applied associate-/r*39.0
rmApplied fma-udef39.0
Applied hypot-def39.0
rmApplied fma-udef39.0
Applied hypot-def25.6
Taylor expanded around inf 16.8
Final simplification13.0
herbie shell --seed 2019129 +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))))