\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \leq -1.5835790079768928 \cdot 10^{+81}:\\
\;\;\;\;\frac{-\mathsf{fma}\left(\frac{c}{d}, a, b\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}\;d \leq -4.914157784902541 \cdot 10^{-154}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 5.0503981640593735 \cdot 10^{-129}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}\\
\mathbf{elif}\;d \leq 1.5945253184501813 \cdot 10^{+119}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\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 (<= d -1.5835790079768928e+81)
(/ (- (fma (/ c d) a b)) (hypot d c))
(let* ((t_0 (/ (/ (fma d b (* c a)) (hypot d c)) (hypot d c))))
(if (<= d -4.914157784902541e-154)
t_0
(if (<= d 5.0503981640593735e-129)
(+ (/ a c) (/ (* d b) (pow c 2.0)))
(if (<= d 1.5945253184501813e+119)
t_0
(fma (/ a d) (/ c d) (/ b d))))))))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 (d <= -1.5835790079768928e+81) {
tmp = -fma((c / d), a, b) / hypot(d, c);
} else {
double t_0 = (fma(d, b, (c * a)) / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (d <= -4.914157784902541e-154) {
tmp_1 = t_0;
} else if (d <= 5.0503981640593735e-129) {
tmp_1 = (a / c) + ((d * b) / pow(c, 2.0));
} else if (d <= 1.5945253184501813e+119) {
tmp_1 = t_0;
} else {
tmp_1 = fma((a / d), (c / d), (b / d));
}
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.2 |
if d < -1.58357900797689277e81Initial program 37.0
Simplified37.0
Applied add-sqr-sqrt_binary6437.0
Applied *-un-lft-identity_binary6437.0
Applied times-frac_binary6437.0
Simplified37.0
Simplified25.1
Applied associate-*l/_binary6425.0
Taylor expanded in d around -inf 13.5
Simplified10.9
if -1.58357900797689277e81 < d < -4.91415778490254085e-154 or 5.05039816405937352e-129 < d < 1.59452531845018132e119Initial program 15.8
Simplified15.8
Applied add-sqr-sqrt_binary6415.8
Applied add-cube-cbrt_binary6416.4
Applied times-frac_binary6416.4
Simplified16.4
Simplified11.6
Applied associate-*l/_binary6411.6
Simplified10.7
if -4.91415778490254085e-154 < d < 5.05039816405937352e-129Initial program 22.9
Simplified22.9
Taylor expanded in c around inf 9.8
if 1.59452531845018132e119 < d Initial program 41.0
Simplified41.0
Applied add-sqr-sqrt_binary6441.0
Applied *-un-lft-identity_binary6441.0
Applied times-frac_binary6441.0
Simplified41.0
Simplified27.6
Taylor expanded in d around inf 16.2
Simplified8.5
Final simplification10.2
herbie shell --seed 2021313
(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))))