\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq -6.326900384087905 \cdot 10^{+99}:\\
\;\;\;\;\frac{b}{d} + \frac{1}{\frac{d}{c \cdot \frac{a}{d}}}\\
\mathbf{elif}\;d \leq -1.571220827360316 \cdot 10^{-157}:\\
\;\;\;\;\frac{\frac{c \cdot a + d \cdot b}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;d \leq 1.0832799013795811 \cdot 10^{-106}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}\\
\mathbf{elif}\;d \leq 2.155918540492542 \cdot 10^{+114}:\\
\;\;\;\;\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{b}{d} + \frac{\frac{a}{d} \cdot \frac{c}{\sqrt[3]{d} \cdot \sqrt[3]{d}}}{\sqrt[3]{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 -6.326900384087905e+99)
(+ (/ b d) (/ 1.0 (/ d (* c (/ a d)))))
(if (<= d -1.571220827360316e-157)
(/
(/ (+ (* c a) (* d b)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(if (<= d 1.0832799013795811e-106)
(+ (/ a c) (/ (* d b) (pow c 2.0)))
(if (<= d 2.155918540492542e+114)
(/
(/ (+ (* c a) (* d b)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(+ (/ b d) (/ (* (/ a d) (/ c (* (cbrt d) (cbrt d)))) (cbrt 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 <= -6.326900384087905e+99) {
tmp = (b / d) + (1.0 / (d / (c * (a / d))));
} else if (d <= -1.571220827360316e-157) {
tmp = (((c * a) + (d * b)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else if (d <= 1.0832799013795811e-106) {
tmp = (a / c) + ((d * b) / pow(c, 2.0));
} else if (d <= 2.155918540492542e+114) {
tmp = (((c * a) + (d * b)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else {
tmp = (b / d) + (((a / d) * (c / (cbrt(d) * cbrt(d)))) / cbrt(d));
}
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 | 12.9 |
if d < -6.32690038408790547e99Initial program 39.9
Taylor expanded around 0 17.1
Simplified17.1
rmApplied associate-/r*_binary64_309114.7
Simplified10.8
rmApplied clear-num_binary64_314610.9
if -6.32690038408790547e99 < d < -1.5712208273603159e-157 or 1.08327990137958106e-106 < d < 2.15591854049254201e114Initial program 16.4
rmApplied add-sqr-sqrt_binary64_316916.4
Applied associate-/r*_binary64_309116.3
if -1.5712208273603159e-157 < d < 1.08327990137958106e-106Initial program 23.3
Taylor expanded around inf 11.0
if 2.15591854049254201e114 < d Initial program 42.2
Taylor expanded around 0 16.8
Simplified16.8
rmApplied associate-/r*_binary64_309114.0
Simplified9.7
rmApplied add-cube-cbrt_binary64_31829.8
Applied associate-/r*_binary64_30919.8
Simplified9.8
Final simplification12.9
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))))