\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.0369714268381499 \cdot 10^{130}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 1.16976921742310533 \cdot 10^{217}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\end{array}double code(double a, double b, double c, double d) {
return ((double) (((double) (((double) (a * c)) + ((double) (b * d)))) / ((double) (((double) (c * c)) + ((double) (d * d))))));
}
double code(double a, double b, double c, double d) {
double VAR;
if ((c <= -2.03697142683815e+130)) {
VAR = ((double) (((double) (-1.0 * a)) / ((double) (((double) hypot(c, d)) * 1.0))));
} else {
double VAR_1;
if ((c <= 1.1697692174231053e+217)) {
VAR_1 = ((double) (((double) (((double) fma(a, c, ((double) (b * d)))) / ((double) hypot(c, d)))) / ((double) (((double) hypot(c, d)) * 1.0))));
} else {
VAR_1 = ((double) (a / ((double) (((double) hypot(c, d)) * 1.0))));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.4 |
|---|---|
| Target | 0.4 |
| Herbie | 13.1 |
if c < -2.03697142683815e+130Initial program 42.9
rmApplied add-sqr-sqrt42.9
Applied *-un-lft-identity42.9
Applied times-frac42.9
Simplified42.9
Simplified29.3
rmApplied associate-*r/29.3
Simplified29.2
Taylor expanded around -inf 15.1
if -2.03697142683815e+130 < c < 1.1697692174231053e+217Initial program 21.2
rmApplied add-sqr-sqrt21.2
Applied *-un-lft-identity21.2
Applied times-frac21.3
Simplified21.3
Simplified13.0
rmApplied associate-*r/13.0
Simplified12.9
if 1.1697692174231053e+217 < c Initial program 44.4
rmApplied add-sqr-sqrt44.4
Applied *-un-lft-identity44.4
Applied times-frac44.4
Simplified44.4
Simplified34.3
rmApplied associate-*r/34.3
Simplified34.3
Taylor expanded around inf 11.4
Final simplification13.1
herbie shell --seed 2020123 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))