\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -9.705756685731516 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(\frac{d}{c}, b, a\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \leq -4.084260136662665 \cdot 10^{-238}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 4.5110647824345223 \cdot 10^{-212}:\\
\;\;\;\;\mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right)\\
\mathbf{elif}\;c \leq 3.408225542871235 \cdot 10^{+180}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{c}, \frac{d}{c}, \frac{a}{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 a c (* d b)) (hypot c d)) (hypot c d))))
(if (<= c -9.705756685731516e+151)
(* (fma (/ d c) b a) (/ -1.0 (hypot c d)))
(if (<= c -4.084260136662665e-238)
t_0
(if (<= c 4.5110647824345223e-212)
(fma (/ a d) (/ c d) (/ b d))
(if (<= c 3.408225542871235e+180)
t_0
(fma (/ b c) (/ d 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 t_0 = (fma(a, c, (d * b)) / hypot(c, d)) / hypot(c, d);
double tmp;
if (c <= -9.705756685731516e+151) {
tmp = fma((d / c), b, a) * (-1.0 / hypot(c, d));
} else if (c <= -4.084260136662665e-238) {
tmp = t_0;
} else if (c <= 4.5110647824345223e-212) {
tmp = fma((a / d), (c / d), (b / d));
} else if (c <= 3.408225542871235e+180) {
tmp = t_0;
} else {
tmp = fma((b / c), (d / c), (a / c));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.4 |
|---|---|
| Target | 0.5 |
| Herbie | 10.4 |
if c < -9.7057566857315155e151Initial program 44.9
Simplified44.9
Applied egg-rr29.5
Taylor expanded in c around -inf 11.3
Simplified7.4
if -9.7057566857315155e151 < c < -4.08426013666266484e-238 or 4.51106478243452233e-212 < c < 3.408225542871235e180Initial program 19.4
Simplified19.4
Applied egg-rr12.5
Applied egg-rr12.4
if -4.08426013666266484e-238 < c < 4.51106478243452233e-212Initial program 23.3
Simplified23.3
Applied egg-rr12.7
Taylor expanded in c around 0 9.2
Simplified6.2
if 3.408225542871235e180 < c Initial program 45.9
Simplified45.9
Applied egg-rr32.3
Taylor expanded in c around inf 14.8
Simplified6.8
Final simplification10.4
herbie shell --seed 2022130
(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))))