\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.565167565781187104932955349587597625361 \cdot 10^{162}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 6.152282888480768325547605387077337858415 \cdot 10^{76}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(c, b, \left(-a\right) \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\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 r83295 = b;
double r83296 = c;
double r83297 = r83295 * r83296;
double r83298 = a;
double r83299 = d;
double r83300 = r83298 * r83299;
double r83301 = r83297 - r83300;
double r83302 = r83296 * r83296;
double r83303 = r83299 * r83299;
double r83304 = r83302 + r83303;
double r83305 = r83301 / r83304;
return r83305;
}
double f(double a, double b, double c, double d) {
double r83306 = c;
double r83307 = -1.5651675657811871e+162;
bool r83308 = r83306 <= r83307;
double r83309 = b;
double r83310 = -r83309;
double r83311 = d;
double r83312 = hypot(r83306, r83311);
double r83313 = r83310 / r83312;
double r83314 = 6.152282888480768e+76;
bool r83315 = r83306 <= r83314;
double r83316 = a;
double r83317 = -r83316;
double r83318 = r83317 * r83311;
double r83319 = fma(r83306, r83309, r83318);
double r83320 = r83319 / r83312;
double r83321 = r83320 / r83312;
double r83322 = r83309 / r83312;
double r83323 = r83315 ? r83321 : r83322;
double r83324 = r83308 ? r83313 : r83323;
return r83324;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.7 |
|---|---|
| Target | 0.3 |
| Herbie | 12.8 |
if c < -1.5651675657811871e+162Initial program 45.9
rmApplied add-sqr-sqrt45.9
Applied *-un-lft-identity45.9
Applied times-frac45.9
Simplified45.9
Simplified30.7
rmApplied associate-*r/30.7
Simplified30.7
Taylor expanded around -inf 13.3
Simplified13.3
if -1.5651675657811871e+162 < c < 6.152282888480768e+76Initial program 18.7
rmApplied add-sqr-sqrt18.7
Applied *-un-lft-identity18.7
Applied times-frac18.7
Simplified18.7
Simplified11.4
rmApplied associate-*r/11.4
Simplified11.3
if 6.152282888480768e+76 < c Initial program 37.3
rmApplied add-sqr-sqrt37.3
Applied *-un-lft-identity37.3
Applied times-frac37.3
Simplified37.3
Simplified26.1
rmApplied associate-*r/26.1
Simplified26.1
Taylor expanded around inf 17.8
Final simplification12.8
herbie shell --seed 2019209 +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))))