\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.01458341645274 \cdot 10^{+165}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 2.0408764461888536 \cdot 10^{+156}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{b \cdot c - a \cdot d}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r2045783 = b;
double r2045784 = c;
double r2045785 = r2045783 * r2045784;
double r2045786 = a;
double r2045787 = d;
double r2045788 = r2045786 * r2045787;
double r2045789 = r2045785 - r2045788;
double r2045790 = r2045784 * r2045784;
double r2045791 = r2045787 * r2045787;
double r2045792 = r2045790 + r2045791;
double r2045793 = r2045789 / r2045792;
return r2045793;
}
double f(double a, double b, double c, double d) {
double r2045794 = c;
double r2045795 = -1.01458341645274e+165;
bool r2045796 = r2045794 <= r2045795;
double r2045797 = b;
double r2045798 = -r2045797;
double r2045799 = d;
double r2045800 = hypot(r2045794, r2045799);
double r2045801 = r2045798 / r2045800;
double r2045802 = 2.0408764461888536e+156;
bool r2045803 = r2045794 <= r2045802;
double r2045804 = 1.0;
double r2045805 = r2045797 * r2045794;
double r2045806 = a;
double r2045807 = r2045806 * r2045799;
double r2045808 = r2045805 - r2045807;
double r2045809 = r2045800 / r2045808;
double r2045810 = r2045804 / r2045809;
double r2045811 = r2045810 / r2045800;
double r2045812 = r2045797 / r2045800;
double r2045813 = r2045803 ? r2045811 : r2045812;
double r2045814 = r2045796 ? r2045801 : r2045813;
return r2045814;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.4 |
| Herbie | 12.8 |
if c < -1.01458341645274e+165Initial program 44.3
rmApplied add-sqr-sqrt44.3
Applied associate-/r*44.3
rmApplied fma-neg44.3
rmApplied hypot-def44.3
Taylor expanded around -inf 12.7
Simplified12.7
if -1.01458341645274e+165 < c < 2.0408764461888536e+156Initial program 19.6
rmApplied add-sqr-sqrt19.6
Applied associate-/r*19.5
rmApplied fma-neg19.5
rmApplied hypot-def19.5
rmApplied clear-num19.6
Simplified12.6
if 2.0408764461888536e+156 < c Initial program 44.7
rmApplied add-sqr-sqrt44.7
Applied associate-/r*44.7
rmApplied fma-neg44.7
rmApplied hypot-def44.7
Taylor expanded around inf 14.0
Final simplification12.8
herbie shell --seed 2019128 +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))))