\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -8.741080840408781 \cdot 10^{174}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 5.2041129564588181 \cdot 10^{39}:\\
\;\;\;\;\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 <= -8.741080840408781e+174)) {
VAR = ((double) (((double) (-1.0 * a)) / ((double) (((double) hypot(c, d)) * 1.0))));
} else {
double VAR_1;
if ((c <= 5.204112956458818e+39)) {
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.5 |
| Herbie | 13.9 |
if c < -8.741080840408781e+174Initial program 43.4
rmApplied add-sqr-sqrt43.4
Applied *-un-lft-identity43.4
Applied times-frac43.4
Simplified43.4
Simplified29.6
rmApplied associate-*r/29.6
Simplified29.5
Taylor expanded around -inf 11.8
if -8.741080840408781e+174 < c < 5.204112956458818e+39Initial program 20.2
rmApplied add-sqr-sqrt20.2
Applied *-un-lft-identity20.2
Applied times-frac20.2
Simplified20.2
Simplified12.2
rmApplied associate-*r/12.2
Simplified12.1
if 5.204112956458818e+39 < c Initial program 35.1
rmApplied add-sqr-sqrt35.1
Applied *-un-lft-identity35.1
Applied times-frac35.1
Simplified35.1
Simplified24.2
rmApplied associate-*r/24.2
Simplified24.2
Taylor expanded around inf 20.3
Final simplification13.9
herbie shell --seed 2020121 +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))))