\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}double f(double a, double b, double c, double d) {
double r3699559 = a;
double r3699560 = c;
double r3699561 = r3699559 * r3699560;
double r3699562 = b;
double r3699563 = d;
double r3699564 = r3699562 * r3699563;
double r3699565 = r3699561 + r3699564;
double r3699566 = r3699560 * r3699560;
double r3699567 = r3699563 * r3699563;
double r3699568 = r3699566 + r3699567;
double r3699569 = r3699565 / r3699568;
return r3699569;
}
double f(double a, double b, double c, double d) {
double r3699570 = a;
double r3699571 = c;
double r3699572 = b;
double r3699573 = d;
double r3699574 = r3699572 * r3699573;
double r3699575 = fma(r3699570, r3699571, r3699574);
double r3699576 = r3699571 * r3699571;
double r3699577 = fma(r3699573, r3699573, r3699576);
double r3699578 = sqrt(r3699577);
double r3699579 = r3699575 / r3699578;
double r3699580 = r3699579 / r3699578;
return r3699580;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.2 |
|---|---|
| Target | 0.3 |
| Herbie | 26.1 |
Initial program 26.2
Simplified26.2
rmApplied add-sqr-sqrt26.2
Applied associate-/r*26.1
Final simplification26.1
herbie shell --seed 2019155 +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))))