\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\frac{\mathsf{fma}\left(\frac{b}{\sqrt{\mathsf{hypot}\left(c, d\right)}}, \frac{c}{\sqrt{\mathsf{hypot}\left(c, d\right)}}, -\frac{d}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right)}{\mathsf{hypot}\left(c, d\right)} + \left(\frac{d}{\sqrt{\mathsf{hypot}\left(c, d\right)}} \cdot \left(\left(-\frac{a}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right) + \frac{a}{\sqrt{\mathsf{hypot}\left(c, d\right)}}\right)\right) \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}double f(double a, double b, double c, double d) {
double r116622 = b;
double r116623 = c;
double r116624 = r116622 * r116623;
double r116625 = a;
double r116626 = d;
double r116627 = r116625 * r116626;
double r116628 = r116624 - r116627;
double r116629 = r116623 * r116623;
double r116630 = r116626 * r116626;
double r116631 = r116629 + r116630;
double r116632 = r116628 / r116631;
return r116632;
}
double f(double a, double b, double c, double d) {
double r116633 = b;
double r116634 = c;
double r116635 = d;
double r116636 = hypot(r116634, r116635);
double r116637 = sqrt(r116636);
double r116638 = r116633 / r116637;
double r116639 = r116634 / r116637;
double r116640 = r116635 / r116637;
double r116641 = a;
double r116642 = r116641 / r116637;
double r116643 = r116640 * r116642;
double r116644 = -r116643;
double r116645 = fma(r116638, r116639, r116644);
double r116646 = r116645 / r116636;
double r116647 = -r116642;
double r116648 = r116647 + r116642;
double r116649 = r116640 * r116648;
double r116650 = 1.0;
double r116651 = r116650 / r116636;
double r116652 = r116649 * r116651;
double r116653 = r116646 + r116652;
return r116653;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.3 |
| Herbie | 0.8 |
Initial program 26.0
rmApplied add-sqr-sqrt26.0
Applied *-un-lft-identity26.0
Applied times-frac26.0
Simplified26.0
Simplified16.8
rmApplied div-sub16.8
rmApplied add-sqr-sqrt16.8
Applied times-frac9.4
Applied add-sqr-sqrt9.5
Applied times-frac0.9
Applied prod-diff0.9
Applied distribute-lft-in0.9
Simplified0.8
Simplified0.8
Final simplification0.8
herbie shell --seed 2019362 +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))))