\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq 1.7331516180898825 \cdot 10^{+56}:\\
\;\;\;\;\frac{\frac{a \cdot c + d \cdot b}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double code(double a, double b, double c, double d) {
return (((double) (((double) (a * c)) + ((double) (b * d)))) / ((double) (((double) (c * c)) + ((double) (d * d)))));
}
double code(double a, double b, double c, double d) {
double VAR;
if ((d <= 1.7331516180898825e+56)) {
VAR = ((((double) (((double) (a * c)) + ((double) (d * b)))) / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))) / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))));
} else {
VAR = (b / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))));
}
return VAR;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.1 |
|---|---|
| Target | 0.5 |
| Herbie | 26.1 |
if d < 1.73315161808988254e56Initial program Error: 23.3 bits
rmApplied add-sqr-sqrtError: 23.3 bits
Applied associate-/r*Error: 23.2 bits
if 1.73315161808988254e56 < d Initial program Error: 36.0 bits
rmApplied add-sqr-sqrtError: 36.0 bits
Applied associate-/r*Error: 36.0 bits
Taylor expanded around 0 Error: 36.5 bits
Final simplificationError: 26.1 bits
herbie shell --seed 2020200
(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))))