\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 28148546215012511376658377374508777472:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\
\end{array}double f(double a, double b, double c, double d) {
double r6218799 = a;
double r6218800 = c;
double r6218801 = r6218799 * r6218800;
double r6218802 = b;
double r6218803 = d;
double r6218804 = r6218802 * r6218803;
double r6218805 = r6218801 + r6218804;
double r6218806 = r6218800 * r6218800;
double r6218807 = r6218803 * r6218803;
double r6218808 = r6218806 + r6218807;
double r6218809 = r6218805 / r6218808;
return r6218809;
}
double f(double a, double b, double c, double d) {
double r6218810 = d;
double r6218811 = 2.814854621501251e+37;
bool r6218812 = r6218810 <= r6218811;
double r6218813 = a;
double r6218814 = c;
double r6218815 = b;
double r6218816 = r6218810 * r6218815;
double r6218817 = fma(r6218813, r6218814, r6218816);
double r6218818 = r6218814 * r6218814;
double r6218819 = fma(r6218810, r6218810, r6218818);
double r6218820 = sqrt(r6218819);
double r6218821 = r6218817 / r6218820;
double r6218822 = r6218821 / r6218820;
double r6218823 = r6218815 / r6218820;
double r6218824 = r6218812 ? r6218822 : r6218823;
return r6218824;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 26.2 |
if d < 2.814854621501251e+37Initial program 22.8
Simplified22.8
rmApplied add-sqr-sqrt22.8
Applied *-un-lft-identity22.8
Applied times-frac22.8
rmApplied associate-*l/22.7
if 2.814854621501251e+37 < d Initial program 35.3
Simplified35.3
rmApplied add-sqr-sqrt35.3
Applied associate-/r*35.3
Taylor expanded around 0 37.0
Final simplification26.2
herbie shell --seed 2019172 +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))))