\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}double f(double a, double b, double c, double d) {
double r4001586 = a;
double r4001587 = c;
double r4001588 = r4001586 * r4001587;
double r4001589 = b;
double r4001590 = d;
double r4001591 = r4001589 * r4001590;
double r4001592 = r4001588 + r4001591;
double r4001593 = r4001587 * r4001587;
double r4001594 = r4001590 * r4001590;
double r4001595 = r4001593 + r4001594;
double r4001596 = r4001592 / r4001595;
return r4001596;
}
double f(double a, double b, double c, double d) {
double r4001597 = a;
double r4001598 = c;
double r4001599 = b;
double r4001600 = d;
double r4001601 = r4001599 * r4001600;
double r4001602 = fma(r4001597, r4001598, r4001601);
double r4001603 = r4001598 * r4001598;
double r4001604 = fma(r4001600, r4001600, r4001603);
double r4001605 = r4001602 / r4001604;
return r4001605;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 25.8 |
Initial program 25.8
Simplified25.8
Final simplification25.8
herbie shell --seed 2019163 +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))))