\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \leq -7.666814711380057 \cdot 10^{+78}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -2.17846808821293 \cdot 10^{-124}:\\
\;\;\;\;\frac{\frac{d \cdot b + c \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;c \leq 7.205564063930503 \cdot 10^{-187}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\\
\mathbf{elif}\;c \leq 8.456689833717296 \cdot 10^{+141}:\\
\;\;\;\;\frac{\frac{d \cdot b + c \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\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 -7.666814711380057e+78)
(/ a c)
(if (<= c -2.17846808821293e-124)
(/
(/ (+ (* d b) (* c a)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(if (<= c 7.205564063930503e-187)
(+ (/ b d) (/ (* c a) (pow d 2.0)))
(if (<= c 8.456689833717296e+141)
(/
(/ (+ (* d b) (* c a)) (sqrt (+ (* c c) (* d d))))
(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 <= -7.666814711380057e+78) {
tmp = a / c;
} else if (c <= -2.17846808821293e-124) {
tmp = (((d * b) + (c * a)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else if (c <= 7.205564063930503e-187) {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
} else if (c <= 8.456689833717296e+141) {
tmp = (((d * b) + (c * a)) / sqrt((c * c) + (d * d))) / 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 | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 15.2 |
if c < -7.6668147113800567e78 or 8.4566898337172956e141 < c Initial program 39.6
Taylor expanded around inf 17.0
if -7.6668147113800567e78 < c < -2.17846808821293002e-124 or 7.20556406393050255e-187 < c < 8.4566898337172956e141Initial program 16.2
rmApplied add-sqr-sqrt_binary6416.2
Applied associate-/r*_binary6416.1
Simplified16.1
rmApplied associate-/l/_binary6416.2
Simplified16.2
rmApplied add-sqr-sqrt_binary6416.2
Applied associate-/r*_binary6416.1
Simplified16.1
if -2.17846808821293002e-124 < c < 7.20556406393050255e-187Initial program 24.0
Taylor expanded around 0 10.4
Final simplification15.2
herbie shell --seed 2021176
(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))))