\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}double f(double a, double b, double c, double d) {
double r5029375 = a;
double r5029376 = c;
double r5029377 = r5029375 * r5029376;
double r5029378 = b;
double r5029379 = d;
double r5029380 = r5029378 * r5029379;
double r5029381 = r5029377 + r5029380;
double r5029382 = r5029376 * r5029376;
double r5029383 = r5029379 * r5029379;
double r5029384 = r5029382 + r5029383;
double r5029385 = r5029381 / r5029384;
return r5029385;
}
double f(double a, double b, double c, double d) {
double r5029386 = a;
double r5029387 = c;
double r5029388 = b;
double r5029389 = d;
double r5029390 = r5029388 * r5029389;
double r5029391 = fma(r5029386, r5029387, r5029390);
double r5029392 = hypot(r5029389, r5029387);
double r5029393 = r5029391 / r5029392;
double r5029394 = r5029393 / r5029392;
return r5029394;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.6 |
|---|---|
| Target | 0.4 |
| Herbie | 16.3 |
Initial program 25.6
Simplified25.6
rmApplied add-sqr-sqrt25.6
Applied associate-/r*25.5
rmApplied *-un-lft-identity25.5
Applied sqrt-prod25.5
Applied associate-/r*25.5
Simplified25.5
rmApplied clear-num25.7
Simplified16.8
rmApplied associate-/r*16.4
Simplified16.3
Final simplification16.3
herbie shell --seed 2019164 +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))))