\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le 6.76697629171698933790750666516049735136 \cdot 10^{58}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\frac{\mathsf{fma}\left(b, c, -d \cdot a\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 r101212 = b;
double r101213 = c;
double r101214 = r101212 * r101213;
double r101215 = a;
double r101216 = d;
double r101217 = r101215 * r101216;
double r101218 = r101214 - r101217;
double r101219 = r101213 * r101213;
double r101220 = r101216 * r101216;
double r101221 = r101219 + r101220;
double r101222 = r101218 / r101221;
return r101222;
}
double f(double a, double b, double c, double d) {
double r101223 = c;
double r101224 = 6.766976291716989e+58;
bool r101225 = r101223 <= r101224;
double r101226 = 1.0;
double r101227 = d;
double r101228 = hypot(r101223, r101227);
double r101229 = b;
double r101230 = a;
double r101231 = r101227 * r101230;
double r101232 = -r101231;
double r101233 = fma(r101229, r101223, r101232);
double r101234 = r101233 / r101228;
double r101235 = r101228 / r101234;
double r101236 = r101226 / r101235;
double r101237 = r101229 / r101228;
double r101238 = r101225 ? r101236 : r101237;
return r101238;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.5 |
|---|---|
| Target | 0.4 |
| Herbie | 15.6 |
if c < 6.766976291716989e+58Initial program 23.7
rmApplied add-sqr-sqrt23.7
Applied *-un-lft-identity23.7
Applied times-frac23.7
Simplified23.7
Simplified14.9
rmApplied associate-*r/14.8
Simplified14.7
rmApplied clear-num15.2
if 6.766976291716989e+58 < c Initial program 36.6
rmApplied add-sqr-sqrt36.6
Applied *-un-lft-identity36.6
Applied times-frac36.6
Simplified36.6
Simplified25.1
rmApplied associate-*r/25.1
Simplified25.0
Taylor expanded around inf 17.0
Final simplification15.6
herbie shell --seed 2019235 +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))))