\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.50079102587126544 \cdot 10^{162}:\\
\;\;\;\;\frac{-1}{\mathsf{hypot}\left(c, d\right)} \cdot b\\
\mathbf{elif}\;c \le 2.9196597497857521 \cdot 10^{126}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, -d, c \cdot b\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 r121305 = b;
double r121306 = c;
double r121307 = r121305 * r121306;
double r121308 = a;
double r121309 = d;
double r121310 = r121308 * r121309;
double r121311 = r121307 - r121310;
double r121312 = r121306 * r121306;
double r121313 = r121309 * r121309;
double r121314 = r121312 + r121313;
double r121315 = r121311 / r121314;
return r121315;
}
double f(double a, double b, double c, double d) {
double r121316 = c;
double r121317 = -1.5007910258712654e+162;
bool r121318 = r121316 <= r121317;
double r121319 = -1.0;
double r121320 = d;
double r121321 = hypot(r121316, r121320);
double r121322 = r121319 / r121321;
double r121323 = b;
double r121324 = r121322 * r121323;
double r121325 = 2.919659749785752e+126;
bool r121326 = r121316 <= r121325;
double r121327 = a;
double r121328 = -r121320;
double r121329 = r121316 * r121323;
double r121330 = fma(r121327, r121328, r121329);
double r121331 = r121330 / r121321;
double r121332 = r121331 / r121321;
double r121333 = r121323 / r121321;
double r121334 = r121326 ? r121332 : r121333;
double r121335 = r121318 ? r121324 : r121334;
return r121335;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.4 |
|---|---|
| Target | 0.5 |
| Herbie | 12.9 |
if c < -1.5007910258712654e+162Initial program 44.7
Simplified44.7
rmApplied add-sqr-sqrt44.7
Applied *-un-lft-identity44.7
Applied times-frac44.7
Simplified44.7
Simplified30.3
Taylor expanded around -inf 13.9
Simplified13.9
if -1.5007910258712654e+162 < c < 2.919659749785752e+126Initial program 19.7
Simplified19.7
rmApplied add-sqr-sqrt19.7
Applied *-un-lft-identity19.7
Applied times-frac19.7
Simplified19.7
Simplified12.5
rmApplied *-un-lft-identity12.5
Applied add-sqr-sqrt12.5
Applied times-frac12.5
Applied associate-*l*12.5
Simplified12.4
if 2.919659749785752e+126 < c Initial program 41.9
Simplified41.9
rmApplied add-sqr-sqrt41.9
Applied *-un-lft-identity41.9
Applied times-frac41.9
Simplified41.9
Simplified28.6
rmApplied *-un-lft-identity28.6
Applied add-sqr-sqrt28.6
Applied times-frac28.6
Applied associate-*l*28.6
Simplified28.6
Taylor expanded around 0 14.3
Final simplification12.9
herbie shell --seed 2019199 +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))))