\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{d}{c}, b, a\right)\\
\mathbf{if}\;c \leq -2.937760174171857 \cdot 10^{+153}:\\
\;\;\;\;\frac{-t_0}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \leq -1.050794049494874 \cdot 10^{-197}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \leq 2.8636600701744714 \cdot 10^{-111}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\\
\mathbf{elif}\;c \leq 1.6628009337917042 \cdot 10^{+133}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{\mathsf{hypot}\left(d, c\right)}\\
\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 (/ d c) b a)))
(if (<= c -2.937760174171857e+153)
(/ (- t_0) (hypot d c))
(if (<= c -1.050794049494874e-197)
(/ (/ (fma d b (* c a)) (hypot d c)) (hypot d c))
(if (<= c 2.8636600701744714e-111)
(+ (/ b d) (/ (* c a) (pow d 2.0)))
(if (<= c 1.6628009337917042e+133)
(/ (/ (fma a c (* d b)) (hypot d c)) (hypot d c))
(/ t_0 (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 t_0 = fma((d / c), b, a);
double tmp;
if (c <= -2.937760174171857e+153) {
tmp = -t_0 / hypot(d, c);
} else if (c <= -1.050794049494874e-197) {
tmp = (fma(d, b, (c * a)) / hypot(d, c)) / hypot(d, c);
} else if (c <= 2.8636600701744714e-111) {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
} else if (c <= 1.6628009337917042e+133) {
tmp = (fma(a, c, (d * b)) / hypot(d, c)) / hypot(d, c);
} else {
tmp = t_0 / hypot(d, c);
}
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.2 |
if c < -2.93776017417185701e153Initial program 44.9
Applied add-sqr-sqrt_binary6444.9
Applied *-un-lft-identity_binary6444.9
Applied times-frac_binary6444.9
Simplified44.9
Simplified28.1
Applied associate-*l/_binary6428.1
Simplified28.1
Taylor expanded in c around -inf 10.9
Simplified7.0
if -2.93776017417185701e153 < c < -1.05079404949487398e-197Initial program 18.7
Applied add-sqr-sqrt_binary6418.7
Applied *-un-lft-identity_binary6418.7
Applied times-frac_binary6418.7
Simplified18.7
Simplified12.9
Applied associate-*l/_binary6412.8
if -1.05079404949487398e-197 < c < 2.86366007017447139e-111Initial program 21.9
Taylor expanded in c around 0 9.3
if 2.86366007017447139e-111 < c < 1.6628009337917042e133Initial program 17.1
Applied add-sqr-sqrt_binary6417.1
Applied *-un-lft-identity_binary6417.1
Applied times-frac_binary6417.1
Simplified17.1
Simplified11.8
Applied associate-*l/_binary6411.7
Simplified11.7
if 1.6628009337917042e133 < c Initial program 44.1
Applied add-sqr-sqrt_binary6444.1
Applied *-un-lft-identity_binary6444.1
Applied times-frac_binary6444.1
Simplified44.1
Simplified29.6
Applied associate-*l/_binary6429.5
Simplified29.5
Taylor expanded in c around inf 11.9
Simplified7.6
Final simplification10.2
herbie shell --seed 2021307
(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))))