\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \leq -4.32818473896838 \cdot 10^{+105}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\mathbf{elif}\;c \leq -9.478533032926856 \cdot 10^{-118}:\\
\;\;\;\;\frac{\frac{c \cdot a + d \cdot b}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;c \leq 1.4206205443431834 \cdot 10^{-192}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\\
\mathbf{elif}\;c \leq 1.0829748826702354 \cdot 10^{-189}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{d \cdot b}{c}}{c}\\
\mathbf{elif}\;c \leq 4.186640121113003 \cdot 10^{-153}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\\
\mathbf{elif}\;c \leq 1.0217963801675215 \cdot 10^{+22}:\\
\;\;\;\;\frac{\frac{c \cdot a + d \cdot b}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\
\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.32818473896838e+105)
(+ (/ a c) (* (/ d c) (/ b c)))
(if (<= c -9.478533032926856e-118)
(/
(/ (+ (* c a) (* d b)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(if (<= c 1.4206205443431834e-192)
(+ (/ b d) (/ (* c a) (pow d 2.0)))
(if (<= c 1.0829748826702354e-189)
(+ (/ a c) (/ (/ (* d b) c) c))
(if (<= c 4.186640121113003e-153)
(+ (/ b d) (/ (* c a) (pow d 2.0)))
(if (<= c 1.0217963801675215e+22)
(/
(/ (+ (* c a) (* d b)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(+ (/ a c) (* (/ d c) (/ b 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.32818473896838e+105) {
tmp = (a / c) + ((d / c) * (b / c));
} else if (c <= -9.478533032926856e-118) {
tmp = (((c * a) + (d * b)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else if (c <= 1.4206205443431834e-192) {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
} else if (c <= 1.0829748826702354e-189) {
tmp = (a / c) + (((d * b) / c) / c);
} else if (c <= 4.186640121113003e-153) {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
} else if (c <= 1.0217963801675215e+22) {
tmp = (((c * a) + (d * b)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else {
tmp = (a / c) + ((d / c) * (b / c));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.7 |
|---|---|
| Target | 0.5 |
| Herbie | 12.9 |
if c < -4.3281847389683799e105 or 1.02179638016752149e22 < c Initial program 37.2
Taylor expanded around inf 17.5
Simplified17.5
rmApplied times-frac_binary64_417612.5
if -4.3281847389683799e105 < c < -9.4785330329268561e-118 or 4.1866401211130029e-153 < c < 1.02179638016752149e22Initial program 15.5
rmApplied add-sqr-sqrt_binary64_419215.5
Applied associate-/r*_binary64_411415.4
if -9.4785330329268561e-118 < c < 1.4206205443431834e-192 or 1.08297488267023536e-189 < c < 4.1866401211130029e-153Initial program 24.1
Taylor expanded around 0 9.8
if 1.4206205443431834e-192 < c < 1.08297488267023536e-189Initial program 30.3
Taylor expanded around inf 64.0
Simplified64.0
rmApplied associate-/r*_binary64_411451.5
Final simplification12.9
herbie shell --seed 2021096
(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))))