\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -2.556682598034695703330250466492269315027 \cdot 10^{120}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \le 5.654413025831701701732390598974065197851 \cdot 10^{178}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(-d, a, c \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r78737 = b;
double r78738 = c;
double r78739 = r78737 * r78738;
double r78740 = a;
double r78741 = d;
double r78742 = r78740 * r78741;
double r78743 = r78739 - r78742;
double r78744 = r78738 * r78738;
double r78745 = r78741 * r78741;
double r78746 = r78744 + r78745;
double r78747 = r78743 / r78746;
return r78747;
}
double f(double a, double b, double c, double d) {
double r78748 = d;
double r78749 = -2.5566825980346957e+120;
bool r78750 = r78748 <= r78749;
double r78751 = a;
double r78752 = c;
double r78753 = hypot(r78752, r78748);
double r78754 = r78751 / r78753;
double r78755 = 5.654413025831702e+178;
bool r78756 = r78748 <= r78755;
double r78757 = -r78748;
double r78758 = b;
double r78759 = r78752 * r78758;
double r78760 = fma(r78757, r78751, r78759);
double r78761 = r78760 / r78753;
double r78762 = r78761 / r78753;
double r78763 = -r78751;
double r78764 = r78763 / r78753;
double r78765 = r78756 ? r78762 : r78764;
double r78766 = r78750 ? r78754 : r78765;
return r78766;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.4 |
|---|---|
| Target | 0.5 |
| Herbie | 12.8 |
if d < -2.5566825980346957e+120Initial program 40.8
rmApplied add-sqr-sqrt40.8
Applied *-un-lft-identity40.8
Applied times-frac40.8
Simplified40.8
Simplified27.0
rmApplied *-un-lft-identity27.0
Applied associate-*l*27.0
Simplified27.0
rmApplied *-un-lft-identity27.0
Taylor expanded around -inf 15.4
if -2.5566825980346957e+120 < d < 5.654413025831702e+178Initial program 20.1
rmApplied add-sqr-sqrt20.1
Applied *-un-lft-identity20.1
Applied times-frac20.1
Simplified20.1
Simplified12.3
rmApplied *-un-lft-identity12.3
Applied associate-*l*12.3
Simplified12.1
rmApplied *-un-lft-identity12.1
if 5.654413025831702e+178 < d Initial program 45.3
rmApplied add-sqr-sqrt45.3
Applied *-un-lft-identity45.3
Applied times-frac45.3
Simplified45.3
Simplified32.6
rmApplied *-un-lft-identity32.6
Applied associate-*l*32.6
Simplified32.6
rmApplied *-un-lft-identity32.6
Taylor expanded around inf 13.3
Simplified13.3
Final simplification12.8
herbie shell --seed 2019174 +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))))