\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq -2.5033965365909377 \cdot 10^{+145}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{\frac{d \cdot d}{c}}\\
\mathbf{elif}\;d \leq -1.1669216222378627 \cdot 10^{-135}:\\
\;\;\;\;\frac{\frac{d \cdot b + a \cdot c}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{elif}\;d \leq 1.0481161816497777 \cdot 10^{-159}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot b}{c \cdot c}\\
\mathbf{elif}\;d \leq 5.454863883134953 \cdot 10^{+45}:\\
\;\;\;\;\frac{\frac{d \cdot b + a \cdot c}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{elif}\;d \leq 4.762697302129139 \cdot 10^{+91}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{\frac{c \cdot c}{d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{a}{\frac{d \cdot d}{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 (<= d -2.5033965365909377e+145)
(+ (/ b d) (/ a (/ (* d d) c)))
(if (<= d -1.1669216222378627e-135)
(/
(/ (+ (* d b) (* a c)) (sqrt (+ (* d d) (* c c))))
(sqrt (+ (* d d) (* c c))))
(if (<= d 1.0481161816497777e-159)
(+ (/ a c) (/ (* d b) (* c c)))
(if (<= d 5.454863883134953e+45)
(/
(/ (+ (* d b) (* a c)) (sqrt (+ (* d d) (* c c))))
(sqrt (+ (* d d) (* c c))))
(if (<= d 4.762697302129139e+91)
(+ (/ a c) (/ b (/ (* c c) d)))
(+ (/ b d) (/ a (/ (* d d) 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 (d <= -2.5033965365909377e+145) {
tmp = (b / d) + (a / ((d * d) / c));
} else if (d <= -1.1669216222378627e-135) {
tmp = (((d * b) + (a * c)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
} else if (d <= 1.0481161816497777e-159) {
tmp = (a / c) + ((d * b) / (c * c));
} else if (d <= 5.454863883134953e+45) {
tmp = (((d * b) + (a * c)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
} else if (d <= 4.762697302129139e+91) {
tmp = (a / c) + (b / ((c * c) / d));
} else {
tmp = (b / d) + (a / ((d * d) / 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.5 |
| Herbie | 15.3 |
if d < -2.5033965365909377e145 or 4.76269730212913932e91 < d Initial program 40.9
rmApplied div-inv_binary64_212140.9
rmApplied add-sqr-sqrt_binary64_214640.9
Applied add-cube-cbrt_binary64_215940.9
Applied times-frac_binary64_213041.0
Applied associate-*r*_binary64_206440.9
Simplified40.9
Taylor expanded around inf 16.4
Simplified15.2
if -2.5033965365909377e145 < d < -1.16692162223786273e-135 or 1.0481161816497777e-159 < d < 5.4548638831349529e45Initial program 16.7
rmApplied add-sqr-sqrt_binary64_214616.7
Applied associate-/r*_binary64_206816.6
Simplified16.6
if -1.16692162223786273e-135 < d < 1.0481161816497777e-159Initial program 23.2
Taylor expanded around inf 9.4
Simplified9.4
if 5.4548638831349529e45 < d < 4.76269730212913932e91Initial program 19.7
rmApplied div-inv_binary64_212119.8
rmApplied add-sqr-sqrt_binary64_214619.8
Applied add-cube-cbrt_binary64_215919.8
Applied times-frac_binary64_213019.9
Applied associate-*r*_binary64_206419.8
Simplified19.8
Taylor expanded around 0 38.8
Simplified37.2
Final simplification15.3
herbie shell --seed 2021025
(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))))