\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq -2.9682609400537914 \cdot 10^{+110}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\mathbf{elif}\;d \leq -3.1632983967499654 \cdot 10^{-102}:\\
\;\;\;\;\frac{\frac{c \cdot a + d \cdot b}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{elif}\;d \leq 3.7484479560584536 \cdot 10^{-146}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot b}{c \cdot c}\\
\mathbf{elif}\;d \leq 1.3239207115659564 \cdot 10^{+69}:\\
\;\;\;\;\frac{\frac{c \cdot a + d \cdot b}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{d}{b}}\\
\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 -2.9682609400537914e+110)
(+ (/ b d) (/ (* c a) (* d d)))
(if (<= d -3.1632983967499654e-102)
(/
(/ (+ (* c a) (* d b)) (sqrt (+ (* d d) (* c c))))
(sqrt (+ (* d d) (* c c))))
(if (<= d 3.7484479560584536e-146)
(+ (/ a c) (/ (* d b) (* c c)))
(if (<= d 1.3239207115659564e+69)
(/
(/ (+ (* c a) (* d b)) (sqrt (+ (* d d) (* c c))))
(sqrt (+ (* d d) (* c c))))
(/ 1.0 (/ d b)))))))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 <= -2.9682609400537914e+110) {
tmp = (b / d) + ((c * a) / (d * d));
} else if (d <= -3.1632983967499654e-102) {
tmp = (((c * a) + (d * b)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
} else if (d <= 3.7484479560584536e-146) {
tmp = (a / c) + ((d * b) / (c * c));
} else if (d <= 1.3239207115659564e+69) {
tmp = (((c * a) + (d * b)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
} else {
tmp = 1.0 / (d / b);
}
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.9 |
if d < -2.9682609400537914e110Initial program 40.4
Taylor expanded around 0 15.3
Simplified15.3
if -2.9682609400537914e110 < d < -3.16329839674996542e-102 or 3.74844795605845357e-146 < d < 1.32392071156595641e69Initial program 15.7
rmApplied add-sqr-sqrt_binary64_316915.7
Applied associate-/r*_binary64_309115.6
if -3.16329839674996542e-102 < d < 3.74844795605845357e-146Initial program 22.6
Taylor expanded around inf 10.9
Simplified10.9
if 1.32392071156595641e69 < d Initial program 37.4
rmApplied clear-num_binary64_314637.6
Simplified37.6
Taylor expanded around 0 18.5
Final simplification14.9
herbie shell --seed 2021043
(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))))