\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \leq -2.7839182926984815 \cdot 10^{+79}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -8.849808015292707 \cdot 10^{-110}:\\
\;\;\;\;\frac{\frac{c \cdot a + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;c \leq 2.1472644582174967 \cdot 10^{-123}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\\
\mathbf{elif}\;c \leq 1.315316451044619 \cdot 10^{+86}:\\
\;\;\;\;\frac{\frac{c \cdot a + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot d}{{c}^{2}}\\
\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 -2.7839182926984815e+79)
(/ a c)
(if (<= c -8.849808015292707e-110)
(/
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(if (<= c 2.1472644582174967e-123)
(+ (/ b d) (/ (* c a) (pow d 2.0)))
(if (<= c 1.315316451044619e+86)
(/
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(+ (/ a c) (/ (* b d) (pow c 2.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 tmp;
if (c <= -2.7839182926984815e+79) {
tmp = a / c;
} else if (c <= -8.849808015292707e-110) {
tmp = (((c * a) + (b * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else if (c <= 2.1472644582174967e-123) {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
} else if (c <= 1.315316451044619e+86) {
tmp = (((c * a) + (b * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else {
tmp = (a / c) + ((b * d) / pow(c, 2.0));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.4 |
| Herbie | 14.3 |
if c < -2.7839182926984815e79Initial program 39.7
Taylor expanded around inf 17.5
if -2.7839182926984815e79 < c < -8.84980801529270659e-110 or 2.1472644582174967e-123 < c < 1.3153164510446189e86Initial program 15.0
rmApplied add-sqr-sqrt_binary64_316915.0
Applied associate-/r*_binary64_309114.9
if -8.84980801529270659e-110 < c < 2.1472644582174967e-123Initial program 21.1
Taylor expanded around 0 10.5
if 1.3153164510446189e86 < c Initial program 38.5
Taylor expanded around inf 15.6
Final simplification14.3
herbie shell --seed 2021044
(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))))