\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -6.67809890291080594 \cdot 10^{97}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{\mathsf{hypot}\left(c, d\right)}}}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, \sqrt{\frac{-1}{c}} \cdot c, d \cdot \left(\sqrt{\frac{-1}{c}} \cdot b\right)\right)}}\\
\mathbf{elif}\;c \le 3.37035099458032735 \cdot 10^{73}:\\
\;\;\;\;\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 <= -6.678098902910806e+97)) {
VAR = ((double) (((double) (1.0 / ((double) sqrt(((double) hypot(c, d)))))) / ((double) (((double) hypot(c, d)) / ((double) fma(a, ((double) (((double) sqrt(((double) (-1.0 / c)))) * c)), ((double) (d * ((double) (((double) sqrt(((double) (-1.0 / c)))) * b))))))))));
} else {
double VAR_1;
if ((c <= 3.3703509945803273e+73)) {
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.6 |
|---|---|
| Target | 0.4 |
| Herbie | 14.2 |
if c < -6.678098902910806e+97Initial program 40.4
rmApplied add-sqr-sqrt40.4
Applied *-un-lft-identity40.4
Applied times-frac40.4
Simplified40.4
Simplified26.9
rmApplied associate-*r/26.8
Simplified26.8
rmApplied add-sqr-sqrt26.9
Applied *-un-lft-identity26.9
Applied times-frac26.9
Applied associate-/l*26.9
Simplified26.9
Taylor expanded around -inf 19.3
Simplified19.3
if -6.678098902910806e+97 < c < 3.3703509945803273e+73Initial program 18.8
rmApplied add-sqr-sqrt18.8
Applied *-un-lft-identity18.8
Applied times-frac18.8
Simplified18.8
Simplified11.6
rmApplied associate-*r/11.6
Simplified11.5
if 3.3703509945803273e+73 < c Initial program 37.6
rmApplied add-sqr-sqrt37.6
Applied *-un-lft-identity37.6
Applied times-frac37.6
Simplified37.6
Simplified26.1
rmApplied associate-*r/26.1
Simplified26.0
Taylor expanded around inf 17.7
Final simplification14.2
herbie shell --seed 2020120 +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))))