\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -2.352328066947031545696719548869417237498 \cdot 10^{129}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;d \le 3.537716084017609608802200540186130786223 \cdot 10^{123}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r128253 = b;
double r128254 = c;
double r128255 = r128253 * r128254;
double r128256 = a;
double r128257 = d;
double r128258 = r128256 * r128257;
double r128259 = r128255 - r128258;
double r128260 = r128254 * r128254;
double r128261 = r128257 * r128257;
double r128262 = r128260 + r128261;
double r128263 = r128259 / r128262;
return r128263;
}
double f(double a, double b, double c, double d) {
double r128264 = d;
double r128265 = -2.3523280669470315e+129;
bool r128266 = r128264 <= r128265;
double r128267 = a;
double r128268 = c;
double r128269 = hypot(r128264, r128268);
double r128270 = r128267 / r128269;
double r128271 = 3.5377160840176096e+123;
bool r128272 = r128264 <= r128271;
double r128273 = -r128267;
double r128274 = b;
double r128275 = r128268 * r128274;
double r128276 = fma(r128273, r128264, r128275);
double r128277 = r128276 / r128269;
double r128278 = r128277 / r128269;
double r128279 = r128273 / r128269;
double r128280 = r128272 ? r128278 : r128279;
double r128281 = r128266 ? r128270 : r128280;
return r128281;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.4 |
|---|---|
| Target | 0.5 |
| Herbie | 12.6 |
if d < -2.3523280669470315e+129Initial program 40.8
Simplified40.8
rmApplied add-sqr-sqrt40.8
Applied *-un-lft-identity40.8
Applied times-frac40.8
Simplified40.8
Simplified26.9
rmApplied associate-*r/26.9
Simplified26.9
Taylor expanded around -inf 14.7
if -2.3523280669470315e+129 < d < 3.5377160840176096e+123Initial program 18.5
Simplified18.5
rmApplied add-sqr-sqrt18.5
Applied *-un-lft-identity18.5
Applied times-frac18.5
Simplified18.5
Simplified11.6
rmApplied associate-*r/11.5
Simplified11.4
if 3.5377160840176096e+123 < d Initial program 40.8
Simplified40.8
rmApplied add-sqr-sqrt40.8
Applied *-un-lft-identity40.8
Applied times-frac40.8
Simplified40.8
Simplified26.4
rmApplied associate-*r/26.3
Simplified26.3
Taylor expanded around inf 15.6
Simplified15.6
Final simplification12.6
herbie shell --seed 2019212 +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))))