\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \leq -1.9291899314496838 \cdot 10^{+93}:\\
\;\;\;\;\frac{c \cdot \frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \frac{\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;c \leq -7.366462231695976 \cdot 10^{-163}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 4.578520467817402 \cdot 10^{-188}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\
\mathbf{elif}\;c \leq 204889703146200.6:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}\\
\end{array}
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(if (<= c -1.9291899314496838e+93)
(/ (* c (/ a (hypot d c))) (hypot d c))
(let* ((t_0 (/ (/ (fma d b (* c a)) (hypot d c)) (hypot d c))))
(if (<= c -7.366462231695976e-163)
t_0
(if (<= c 4.578520467817402e-188)
(fma (/ c d) (/ a d) (/ b d))
(if (<= c 204889703146200.6)
t_0
(/ (fma (/ d c) b a) (hypot d c))))))))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 tmp;
if (c <= -1.9291899314496838e+93) {
tmp = (c * (a / hypot(d, c))) / hypot(d, c);
} else {
double t_0 = (fma(d, b, (c * a)) / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (c <= -7.366462231695976e-163) {
tmp_1 = t_0;
} else if (c <= 4.578520467817402e-188) {
tmp_1 = fma((c / d), (a / d), (b / d));
} else if (c <= 204889703146200.6) {
tmp_1 = t_0;
} else {
tmp_1 = fma((d / c), b, a) / hypot(d, c);
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.7 |
|---|---|
| Target | 0.5 |
| Herbie | 10.6 |
if c < -1.92918993144968375e93Initial program 38.5
rmApplied add-sqr-sqrt_binary6438.5
Applied *-un-lft-identity_binary6438.5
Applied times-frac_binary6438.5
Simplified38.5
Simplified25.0
Taylor expanded in d around 0 32.5
Simplified13.1
if -1.92918993144968375e93 < c < -7.3664622316959762e-163 or 4.578520467817402e-188 < c < 204889703146200.594Initial program 15.4
rmApplied add-sqr-sqrt_binary6415.4
Applied *-un-lft-identity_binary6415.4
Applied times-frac_binary6415.4
Simplified15.4
Simplified10.2
rmApplied *-un-lft-identity_binary6410.2
Applied associate-*l*_binary6410.2
Simplified10.1
if -7.3664622316959762e-163 < c < 4.578520467817402e-188Initial program 24.3
Taylor expanded in c around 0 8.2
Simplified5.6
if 204889703146200.594 < c Initial program 32.5
rmApplied add-sqr-sqrt_binary6432.5
Applied *-un-lft-identity_binary6432.5
Applied times-frac_binary6432.5
Simplified32.5
Simplified22.6
Taylor expanded in d around 0 16.4
Simplified13.5
Final simplification10.6
herbie shell --seed 2021211
(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))))