\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le 5.8823126479882652 \cdot 10^{125}:\\
\;\;\;\;\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 (((a * c) + (b * d)) / ((c * c) + (d * d)));
}
double code(double a, double b, double c, double d) {
double temp;
if ((c <= 5.882312647988265e+125)) {
temp = ((fma(a, c, (b * d)) / hypot(c, d)) / (hypot(c, d) * 1.0));
} else {
temp = (a / (hypot(c, d) * 1.0));
}
return temp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.4 |
|---|---|
| Target | 0.5 |
| Herbie | 15.1 |
if c < 5.882312647988265e+125Initial program 23.3
rmApplied add-sqr-sqrt23.3
Applied *-un-lft-identity23.3
Applied times-frac23.3
Simplified23.3
Simplified15.3
rmApplied associate-*r/15.3
Simplified15.2
if 5.882312647988265e+125 < c Initial program 42.7
rmApplied add-sqr-sqrt42.7
Applied *-un-lft-identity42.7
Applied times-frac42.7
Simplified42.7
Simplified28.2
rmApplied associate-*r/28.2
Simplified28.1
Taylor expanded around inf 14.8
Final simplification15.1
herbie shell --seed 2020065 +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))))