\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -4.2293107756407222 \cdot 10^{47} \lor \neg \left(c \le 9.94539393289035303 \cdot 10^{36}\right):\\
\;\;\;\;\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) + \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)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r108713 = b;
double r108714 = c;
double r108715 = r108713 * r108714;
double r108716 = a;
double r108717 = d;
double r108718 = r108716 * r108717;
double r108719 = r108715 - r108718;
double r108720 = r108714 * r108714;
double r108721 = r108717 * r108717;
double r108722 = r108720 + r108721;
double r108723 = r108719 / r108722;
return r108723;
}
double f(double a, double b, double c, double d) {
double r108724 = c;
double r108725 = -4.229310775640722e+47;
bool r108726 = r108724 <= r108725;
double r108727 = 9.945393932890353e+36;
bool r108728 = r108724 <= r108727;
double r108729 = !r108728;
bool r108730 = r108726 || r108729;
double r108731 = b;
double r108732 = d;
double r108733 = hypot(r108724, r108732);
double r108734 = sqrt(r108733);
double r108735 = r108731 / r108734;
double r108736 = r108724 / r108734;
double r108737 = r108732 / r108734;
double r108738 = a;
double r108739 = r108738 / r108734;
double r108740 = r108737 * r108739;
double r108741 = -r108740;
double r108742 = fma(r108735, r108736, r108741);
double r108743 = -r108739;
double r108744 = r108743 + r108739;
double r108745 = r108737 * r108744;
double r108746 = r108742 + r108745;
double r108747 = r108746 / r108733;
double r108748 = r108731 * r108724;
double r108749 = r108748 / r108733;
double r108750 = r108733 / r108732;
double r108751 = r108738 / r108750;
double r108752 = r108749 - r108751;
double r108753 = r108752 / r108733;
double r108754 = r108730 ? r108747 : r108753;
return r108754;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.4 |
|---|---|
| Target | 0.4 |
| Herbie | 0.9 |
if c < -4.229310775640722e+47 or 9.945393932890353e+36 < c Initial program 35.7
rmApplied add-sqr-sqrt35.7
Applied *-un-lft-identity35.7
Applied times-frac35.7
Simplified35.7
Simplified24.6
rmApplied associate-*r/24.5
Simplified24.5
rmApplied div-sub24.5
rmApplied add-sqr-sqrt24.5
Applied times-frac18.9
Applied add-sqr-sqrt19.0
Applied times-frac0.5
Applied prod-diff0.5
Simplified0.5
if -4.229310775640722e+47 < c < 9.945393932890353e+36Initial program 18.5
rmApplied add-sqr-sqrt18.5
Applied *-un-lft-identity18.5
Applied times-frac18.6
Simplified18.6
Simplified10.9
rmApplied associate-*r/10.9
Simplified10.8
rmApplied div-sub10.8
rmApplied associate-/l*1.3
Final simplification0.9
herbie shell --seed 2020081 +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))))