\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \leq -1.3977594964147 \cdot 10^{+95}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.3087003290237327 \cdot 10^{-72}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\\
\mathbf{elif}\;c \leq 7.644444375681995 \cdot 10^{+23}:\\
\;\;\;\;\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 1.9371910220821266 \cdot 10^{+92}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 2.665235252998217 \cdot 10^{+132}:\\
\;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c \cdot a + b \cdot d}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{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 -1.3977594964147e+95)
(/ a c)
(if (<= c 1.3087003290237327e-72)
(+ (/ b d) (/ (* c a) (pow d 2.0)))
(if (<= c 7.644444375681995e+23)
(/
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(if (<= c 1.9371910220821266e+92)
(/ b d)
(if (<= c 2.665235252998217e+132)
(*
(/ 1.0 (sqrt (+ (* c c) (* d d))))
(/
(+ (* c a) (* b d))
(*
(sqrt (sqrt (+ (* c c) (* d d))))
(sqrt (sqrt (+ (* c c) (* d d)))))))
(/ 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 tmp;
if (c <= -1.3977594964147e+95) {
tmp = a / c;
} else if (c <= 1.3087003290237327e-72) {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
} else if (c <= 7.644444375681995e+23) {
tmp = (((c * a) + (b * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else if (c <= 1.9371910220821266e+92) {
tmp = b / d;
} else if (c <= 2.665235252998217e+132) {
tmp = (1.0 / sqrt((c * c) + (d * d))) * (((c * a) + (b * d)) / (sqrt(sqrt((c * c) + (d * d))) * sqrt(sqrt((c * c) + (d * d)))));
} else {
tmp = a / c;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.9 |
|---|---|
| Target | 0.5 |
| Herbie | 20.3 |
if c < -1.3977594964146999e95 or 2.6652352529982171e132 < c Initial program 41.9
Taylor expanded around inf 18.0
if -1.3977594964146999e95 < c < 1.30870032902373269e-72Initial program 19.8
Taylor expanded around 0 20.0
if 1.30870032902373269e-72 < c < 7.6444443756819951e23Initial program 14.8
rmApplied add-sqr-sqrt_binary64_316914.8
Applied associate-/r*_binary64_309114.7
if 7.6444443756819951e23 < c < 1.9371910220821266e92Initial program 20.6
Taylor expanded around 0 41.0
if 1.9371910220821266e92 < c < 2.6652352529982171e132Initial program 24.0
rmApplied add-sqr-sqrt_binary64_316924.0
Applied *-un-lft-identity_binary64_314724.0
Applied times-frac_binary64_315324.0
Simplified24.0
rmApplied add-sqr-sqrt_binary64_316924.2
Final simplification20.3
herbie shell --seed 2021032
(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))))