\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.022076645889743 \cdot 10^{180}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 6.19037942893981855 \cdot 10^{130}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, c, -d \cdot a\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 r161697 = b;
double r161698 = c;
double r161699 = r161697 * r161698;
double r161700 = a;
double r161701 = d;
double r161702 = r161700 * r161701;
double r161703 = r161699 - r161702;
double r161704 = r161698 * r161698;
double r161705 = r161701 * r161701;
double r161706 = r161704 + r161705;
double r161707 = r161703 / r161706;
return r161707;
}
double f(double a, double b, double c, double d) {
double r161708 = c;
double r161709 = -1.022076645889743e+180;
bool r161710 = r161708 <= r161709;
double r161711 = b;
double r161712 = -r161711;
double r161713 = d;
double r161714 = hypot(r161708, r161713);
double r161715 = r161712 / r161714;
double r161716 = 6.190379428939819e+130;
bool r161717 = r161708 <= r161716;
double r161718 = a;
double r161719 = r161713 * r161718;
double r161720 = -r161719;
double r161721 = fma(r161711, r161708, r161720);
double r161722 = r161721 / r161714;
double r161723 = r161722 / r161714;
double r161724 = r161711 / r161714;
double r161725 = r161717 ? r161723 : r161724;
double r161726 = r161710 ? r161715 : r161725;
return r161726;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.7 |
|---|---|
| Target | 0.6 |
| Herbie | 13.3 |
if c < -1.022076645889743e+180Initial program 45.6
rmApplied add-sqr-sqrt45.6
Applied *-un-lft-identity45.6
Applied times-frac45.6
Simplified45.6
Simplified32.3
rmApplied associate-*r/32.3
Simplified32.2
Taylor expanded around -inf 12.9
Simplified12.9
if -1.022076645889743e+180 < c < 6.190379428939819e+130Initial program 21.0
rmApplied add-sqr-sqrt21.0
Applied *-un-lft-identity21.0
Applied times-frac21.1
Simplified21.0
Simplified13.3
rmApplied associate-*r/13.2
Simplified13.1
if 6.190379428939819e+130 < c Initial program 40.4
rmApplied add-sqr-sqrt40.4
Applied *-un-lft-identity40.4
Applied times-frac40.4
Simplified40.4
Simplified25.9
rmApplied associate-*r/25.9
Simplified25.8
Taylor expanded around inf 14.6
Final simplification13.3
herbie shell --seed 2020046 +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))))