\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \leq -4.3216122432969205 \cdot 10^{+170}:\\
\;\;\;\;\mathsf{fma}\left(\frac{d}{c}, b, a\right) \cdot \frac{-1}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \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}\;c \leq -9.690011489311247 \cdot 10^{-152}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.2661331500288663 \cdot 10^{-210}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\
\mathbf{elif}\;c \leq 3.6305850563522157 \cdot 10^{+137}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{d}{c}, \frac{b}{c}, \frac{a}{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 -4.3216122432969205e+170)
(* (fma (/ d c) b a) (/ -1.0 (hypot d c)))
(let* ((t_0 (/ (/ (fma a c (* d b)) (hypot d c)) (hypot d c))))
(if (<= c -9.690011489311247e-152)
t_0
(if (<= c 1.2661331500288663e-210)
(fma (/ c d) (/ a d) (/ b d))
(if (<= c 3.6305850563522157e+137)
t_0
(fma (/ d c) (/ b c) (/ a 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 <= -4.3216122432969205e+170) {
tmp = fma((d / c), b, a) * (-1.0 / hypot(d, c));
} else {
double t_0 = (fma(a, c, (d * b)) / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (c <= -9.690011489311247e-152) {
tmp_1 = t_0;
} else if (c <= 1.2661331500288663e-210) {
tmp_1 = fma((c / d), (a / d), (b / d));
} else if (c <= 3.6305850563522157e+137) {
tmp_1 = t_0;
} else {
tmp_1 = fma((d / c), (b / c), (a / c));
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.4 |
|---|---|
| Target | 0.4 |
| Herbie | 10.4 |
if c < -4.3216122432969205e170Initial program 43.3
Applied add-sqr-sqrt_binary6443.3
Applied *-un-lft-identity_binary6443.3
Applied times-frac_binary6443.3
Simplified43.3
Simplified28.9
Taylor expanded in c around -inf 10.9
Simplified6.0
if -4.3216122432969205e170 < c < -9.690011489311247e-152 or 1.26613315002886632e-210 < c < 3.63058505635221573e137Initial program 19.2
Applied add-sqr-sqrt_binary6419.2
Applied *-un-lft-identity_binary6419.2
Applied times-frac_binary6419.3
Simplified19.3
Simplified13.3
Applied associate-*l/_binary6413.1
Simplified13.1
if -9.690011489311247e-152 < c < 1.26613315002886632e-210Initial program 25.0
Taylor expanded in c around 0 9.6
Simplified7.1
if 3.63058505635221573e137 < c Initial program 42.6
Taylor expanded in c around inf 15.4
Simplified7.6
Final simplification10.4
herbie shell --seed 2021344
(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))))