\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right)\\
\mathbf{if}\;d \leq -2.9753592065970103 \cdot 10^{+133}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;d \leq -3.2778058876870277 \cdot 10^{-146}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;d \leq 8.257594576029714 \cdot 10^{-210}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{c}, \frac{d}{c}, \frac{a}{c}\right)\\
\mathbf{elif}\;d \leq 9.252763405738269 \cdot 10^{+125}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\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
(let* ((t_0 (fma (/ a d) (/ c d) (/ b d))))
(if (<= d -2.9753592065970103e+133)
t_0
(let* ((t_1 (/ (/ (fma a c (* d b)) (hypot d c)) (hypot d c))))
(if (<= d -3.2778058876870277e-146)
t_1
(if (<= d 8.257594576029714e-210)
(fma (/ b c) (/ d c) (/ a c))
(if (<= d 9.252763405738269e+125) t_1 t_0)))))))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 t_0 = fma((a / d), (c / d), (b / d));
double tmp;
if (d <= -2.9753592065970103e+133) {
tmp = t_0;
} else {
double t_1 = (fma(a, c, (d * b)) / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (d <= -3.2778058876870277e-146) {
tmp_1 = t_1;
} else if (d <= 8.257594576029714e-210) {
tmp_1 = fma((b / c), (d / c), (a / c));
} else if (d <= 9.252763405738269e+125) {
tmp_1 = t_1;
} else {
tmp_1 = t_0;
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.5 |
|---|---|
| Target | 0.4 |
| Herbie | 9.6 |
if d < -2.97535920659701029e133 or 9.25276340573826909e125 < d Initial program 42.6
Simplified42.6
Applied add-sqr-sqrt_binary6442.6
Applied *-un-lft-identity_binary6442.6
Applied times-frac_binary6442.6
Simplified42.6
Simplified28.1
Taylor expanded in d around inf 15.7
Simplified7.8
if -2.97535920659701029e133 < d < -3.2778058876870277e-146 or 8.25759457602971357e-210 < d < 9.25276340573826909e125Initial program 17.4
Simplified17.4
Applied add-sqr-sqrt_binary6417.4
Applied *-un-lft-identity_binary6417.4
Applied times-frac_binary6417.4
Simplified17.4
Simplified11.6
Applied associate-*l/_binary6411.5
Simplified11.5
if -3.2778058876870277e-146 < d < 8.25759457602971357e-210Initial program 24.0
Simplified24.0
Applied add-sqr-sqrt_binary6424.0
Applied *-un-lft-identity_binary6424.0
Applied times-frac_binary6424.0
Simplified24.0
Simplified13.2
Taylor expanded in d around 0 10.5
Simplified7.9
Final simplification9.6
herbie shell --seed 2022067
(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))))