\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot b - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}double f(double a, double b, double c, double d) {
double r80910 = b;
double r80911 = c;
double r80912 = r80910 * r80911;
double r80913 = a;
double r80914 = d;
double r80915 = r80913 * r80914;
double r80916 = r80912 - r80915;
double r80917 = r80911 * r80911;
double r80918 = r80914 * r80914;
double r80919 = r80917 + r80918;
double r80920 = r80916 / r80919;
return r80920;
}
double f(double a, double b, double c, double d) {
double r80921 = c;
double r80922 = d;
double r80923 = hypot(r80921, r80922);
double r80924 = r80921 / r80923;
double r80925 = b;
double r80926 = r80924 * r80925;
double r80927 = a;
double r80928 = r80927 / r80923;
double r80929 = r80922 * r80928;
double r80930 = r80926 - r80929;
double r80931 = r80930 / r80923;
return r80931;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.2 |
|---|---|
| Target | 0.5 |
| Herbie | 0.9 |
Initial program 26.2
Simplified26.2
rmApplied add-sqr-sqrt26.2
Applied *-un-lft-identity26.2
Applied times-frac26.2
Simplified26.2
Simplified17.0
rmApplied pow117.0
Applied pow117.0
Applied pow-prod-down17.0
Simplified16.9
rmApplied div-sub16.9
Simplified9.9
Simplified1.3
rmApplied associate-/r/0.9
Final simplification0.9
herbie shell --seed 2019325 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
: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))))