\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{\frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \mathsf{fma}\left(b, c, \left(-a\right) \cdot d\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}double f(double a, double b, double c, double d) {
double r2919497 = b;
double r2919498 = c;
double r2919499 = r2919497 * r2919498;
double r2919500 = a;
double r2919501 = d;
double r2919502 = r2919500 * r2919501;
double r2919503 = r2919499 - r2919502;
double r2919504 = r2919498 * r2919498;
double r2919505 = r2919501 * r2919501;
double r2919506 = r2919504 + r2919505;
double r2919507 = r2919503 / r2919506;
return r2919507;
}
double f(double a, double b, double c, double d) {
double r2919508 = 1.0;
double r2919509 = d;
double r2919510 = c;
double r2919511 = r2919510 * r2919510;
double r2919512 = fma(r2919509, r2919509, r2919511);
double r2919513 = sqrt(r2919512);
double r2919514 = r2919508 / r2919513;
double r2919515 = b;
double r2919516 = a;
double r2919517 = -r2919516;
double r2919518 = r2919517 * r2919509;
double r2919519 = fma(r2919515, r2919510, r2919518);
double r2919520 = r2919514 * r2919519;
double r2919521 = r2919520 / r2919513;
return r2919521;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.4 |
|---|---|
| Target | 0.4 |
| Herbie | 25.4 |
Initial program 25.4
Simplified25.4
rmApplied add-sqr-sqrt25.4
Applied associate-/r*25.3
rmApplied fma-neg25.3
rmApplied div-inv25.4
Final simplification25.4
herbie shell --seed 2019152 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, imag part"
:herbie-target
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))