\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -5.089145779830487536688267543405577993059 \cdot 10^{131}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.608222828046577445825524961558493147213 \cdot 10^{194}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r95664 = b;
double r95665 = c;
double r95666 = r95664 * r95665;
double r95667 = a;
double r95668 = d;
double r95669 = r95667 * r95668;
double r95670 = r95666 - r95669;
double r95671 = r95665 * r95665;
double r95672 = r95668 * r95668;
double r95673 = r95671 + r95672;
double r95674 = r95670 / r95673;
return r95674;
}
double f(double a, double b, double c, double d) {
double r95675 = c;
double r95676 = -5.0891457798304875e+131;
bool r95677 = r95675 <= r95676;
double r95678 = b;
double r95679 = -r95678;
double r95680 = d;
double r95681 = hypot(r95680, r95675);
double r95682 = r95679 / r95681;
double r95683 = 1.6082228280465774e+194;
bool r95684 = r95675 <= r95683;
double r95685 = r95678 * r95675;
double r95686 = a;
double r95687 = r95686 * r95680;
double r95688 = r95685 - r95687;
double r95689 = r95688 / r95681;
double r95690 = r95689 / r95681;
double r95691 = r95678 / r95681;
double r95692 = r95684 ? r95690 : r95691;
double r95693 = r95677 ? r95682 : r95692;
return r95693;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 12.6 |
if c < -5.0891457798304875e+131Initial program 42.5
Simplified42.5
rmApplied add-sqr-sqrt42.5
Applied *-un-lft-identity42.5
Applied times-frac42.5
Simplified42.5
Simplified27.7
rmApplied associate-*r/27.7
Simplified27.6
Taylor expanded around -inf 13.4
Simplified13.4
if -5.0891457798304875e+131 < c < 1.6082228280465774e+194Initial program 20.4
Simplified20.4
rmApplied add-sqr-sqrt20.4
Applied *-un-lft-identity20.4
Applied times-frac20.4
Simplified20.4
Simplified12.8
rmApplied associate-*r/12.8
Simplified12.7
if 1.6082228280465774e+194 < c Initial program 42.7
Simplified42.7
rmApplied add-sqr-sqrt42.7
Applied *-un-lft-identity42.7
Applied times-frac42.7
Simplified42.7
Simplified31.0
rmApplied associate-*r/31.0
Simplified30.9
Taylor expanded around inf 10.7
Final simplification12.6
herbie shell --seed 2019323 +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))))