\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq -1.7122153695293727 \cdot 10^{+103}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -6.029624906319389 \cdot 10^{-162}:\\
\;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c \cdot a + d \cdot b}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;d \leq 2.7322757867875484 \cdot 10^{-28}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}\\
\mathbf{elif}\;d \leq 2.4603004612766966 \cdot 10^{+68}:\\
\;\;\;\;\frac{c \cdot a}{{c}^{2} + {d}^{2}} + \frac{d \cdot b}{{c}^{2} + {d}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{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 (<= d -1.7122153695293727e+103)
(/ b d)
(if (<= d -6.029624906319389e-162)
(*
(/ 1.0 (sqrt (+ (* c c) (* d d))))
(/ (+ (* c a) (* d b)) (sqrt (+ (* c c) (* d d)))))
(if (<= d 2.7322757867875484e-28)
(+ (/ a c) (/ (* d b) (pow c 2.0)))
(if (<= d 2.4603004612766966e+68)
(+
(/ (* c a) (+ (pow c 2.0) (pow d 2.0)))
(/ (* d b) (+ (pow c 2.0) (pow d 2.0))))
(+ (/ b d) (/ (* c a) (pow d 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 (d <= -1.7122153695293727e+103) {
tmp = b / d;
} else if (d <= -6.029624906319389e-162) {
tmp = (1.0 / sqrt((c * c) + (d * d))) * (((c * a) + (d * b)) / sqrt((c * c) + (d * d)));
} else if (d <= 2.7322757867875484e-28) {
tmp = (a / c) + ((d * b) / pow(c, 2.0));
} else if (d <= 2.4603004612766966e+68) {
tmp = ((c * a) / (pow(c, 2.0) + pow(d, 2.0))) + ((d * b) / (pow(c, 2.0) + pow(d, 2.0)));
} else {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.1 |
|---|---|
| Target | 0.4 |
| Herbie | 15.7 |
if d < -1.71221536952937269e103Initial program 40.9
Taylor expanded around 0 18.8
if -1.71221536952937269e103 < d < -6.02962490631938915e-162Initial program 15.3
rmApplied add-sqr-sqrt_binary64_282815.3
Applied *-un-lft-identity_binary64_280615.3
Applied times-frac_binary64_281215.3
if -6.02962490631938915e-162 < d < 2.7322757867875484e-28Initial program 21.1
Taylor expanded around inf 13.2
if 2.7322757867875484e-28 < d < 2.46030046127669663e68Initial program 15.4
Taylor expanded around 0 15.4
if 2.46030046127669663e68 < d Initial program 36.9
Taylor expanded around 0 17.4
Final simplification15.7
herbie shell --seed 2021045
(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))))