\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{\frac{\mathsf{fma}\left(a, c, \left(b \cdot d\right)\right)}{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}}{\sqrt{\mathsf{fma}\left(d, d, \left(c \cdot c\right)\right)}}double f(double a, double b, double c, double d) {
double r3491812 = a;
double r3491813 = c;
double r3491814 = r3491812 * r3491813;
double r3491815 = b;
double r3491816 = d;
double r3491817 = r3491815 * r3491816;
double r3491818 = r3491814 + r3491817;
double r3491819 = r3491813 * r3491813;
double r3491820 = r3491816 * r3491816;
double r3491821 = r3491819 + r3491820;
double r3491822 = r3491818 / r3491821;
return r3491822;
}
double f(double a, double b, double c, double d) {
double r3491823 = a;
double r3491824 = c;
double r3491825 = b;
double r3491826 = d;
double r3491827 = r3491825 * r3491826;
double r3491828 = fma(r3491823, r3491824, r3491827);
double r3491829 = r3491824 * r3491824;
double r3491830 = fma(r3491826, r3491826, r3491829);
double r3491831 = sqrt(r3491830);
double r3491832 = r3491828 / r3491831;
double r3491833 = r3491832 / r3491831;
return r3491833;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.7 |
|---|---|
| Target | 0.4 |
| Herbie | 25.6 |
Initial program 25.7
Simplified25.7
rmApplied add-sqr-sqrt25.7
Applied associate-/r*25.6
Final simplification25.6
herbie shell --seed 2019132 +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))))