\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \leq -2.7839182926984815 \cdot 10^{+79}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -8.849808015292707 \cdot 10^{-110}:\\
\;\;\;\;\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 2.1472644582174967 \cdot 10^{-123}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{d \cdot d}\\
\mathbf{elif}\;c \leq 1.315316451044619 \cdot 10^{+86}:\\
\;\;\;\;\frac{\frac{c \cdot a + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{b \cdot d}{c \cdot 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 -2.7839182926984815e+79)
(/ a c)
(if (<= c -8.849808015292707e-110)
(/
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(if (<= c 2.1472644582174967e-123)
(+ (/ b d) (/ (* c a) (* d d)))
(if (<= c 1.315316451044619e+86)
(/
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(+ (/ a c) (/ (* b d) (* c 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 <= -2.7839182926984815e+79) {
tmp = a / c;
} else if (c <= -8.849808015292707e-110) {
tmp = (((c * a) + (b * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else if (c <= 2.1472644582174967e-123) {
tmp = (b / d) + ((c * a) / (d * d));
} else if (c <= 1.315316451044619e+86) {
tmp = (((c * a) + (b * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else {
tmp = (a / c) + ((b * d) / (c * c));
}
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.3 |
| Alternative 1 | |
|---|---|
| Error | 14.3 |
| Cost | 2372 |
| Alternative 2 | |
|---|---|
| Error | 14.4 |
| Cost | 2244 |
| Alternative 3 | |
|---|---|
| Error | 19.1 |
| Cost | 2630 |
| Alternative 4 | |
|---|---|
| Error | 20.2 |
| Cost | 1750 |
| Alternative 5 | |
|---|---|
| Error | 22.5 |
| Cost | 1562 |
| Alternative 6 | |
|---|---|
| Error | 23.6 |
| Cost | 785 |
| Alternative 7 | |
|---|---|
| Error | 35.3 |
| Cost | 513 |
| Alternative 8 | |
|---|---|
| Error | 52.3 |
| Cost | 64 |
| Alternative 9 | |
|---|---|
| Error | 61.7 |
| Cost | 64 |

if c < -2.7839182926984815e79Initial program 39.7
Taylor expanded around inf 17.5
Simplified17.5
if -2.7839182926984815e79 < c < -8.84980801529270659e-110 or 2.1472644582174967e-123 < c < 1.3153164510446189e86Initial program 15.0
rmApplied add-sqr-sqrt_binary64_385115.0
Applied associate-/r*_binary64_377314.9
Simplified14.9
if -8.84980801529270659e-110 < c < 2.1472644582174967e-123Initial program 21.1
Taylor expanded around 0 10.5
Simplified10.5
Simplified10.5
if 1.3153164510446189e86 < c Initial program 38.5
Taylor expanded around inf 15.6
Simplified15.6
Simplified15.6
Final simplification14.3
herbie shell --seed 2021044
(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))))