\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq -3.6836303645104744 \cdot 10^{+137}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -1.005001047695393 \cdot 10^{-161}:\\
\;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d \cdot b + c \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;d \leq 1.1429473994431096 \cdot 10^{-145}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot b}{c \cdot c}\\
\mathbf{elif}\;d \leq 4.621378501818419 \cdot 10^{+44}:\\
\;\;\;\;\frac{\frac{d \cdot b + c \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\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 (<= d -3.6836303645104744e+137)
(/ b d)
(if (<= d -1.005001047695393e-161)
(*
(/ 1.0 (sqrt (+ (* c c) (* d d))))
(/ (+ (* d b) (* c a)) (sqrt (+ (* c c) (* d d)))))
(if (<= d 1.1429473994431096e-145)
(+ (/ a c) (/ (* d b) (* c c)))
(if (<= d 4.621378501818419e+44)
(/
(/ (+ (* d b) (* c a)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(+ (/ b d) (/ (* c a) (* d d))))))))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 (d <= -3.6836303645104744e+137) {
tmp = b / d;
} else if (d <= -1.005001047695393e-161) {
tmp = (1.0 / sqrt((c * c) + (d * d))) * (((d * b) + (c * a)) / sqrt((c * c) + (d * d)));
} else if (d <= 1.1429473994431096e-145) {
tmp = (a / c) + ((d * b) / (c * c));
} else if (d <= 4.621378501818419e+44) {
tmp = (((d * b) + (c * a)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else {
tmp = (b / d) + ((c * a) / (d * d));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 14.5 |
if d < -3.6836303645104744e137Initial program 43.5
Taylor expanded around 0 15.0
if -3.6836303645104744e137 < d < -1.00500104769539303e-161Initial program 16.5
rmApplied add-sqr-sqrt_binary64_180516.5
Applied *-un-lft-identity_binary64_178316.5
Applied times-frac_binary64_178916.5
Simplified16.5
if -1.00500104769539303e-161 < d < 1.1429473994431096e-145Initial program 23.6
Taylor expanded around inf 9.3
Simplified9.3
if 1.1429473994431096e-145 < d < 4.6213785018184189e44Initial program 14.1
rmApplied add-sqr-sqrt_binary64_180514.1
Applied associate-/r*_binary64_172714.0
if 4.6213785018184189e44 < d Initial program 34.6
Taylor expanded around 0 17.1
Simplified17.1
Final simplification14.5
herbie shell --seed 2021022
(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))))