\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} = -inf.0:\\
\;\;\;\;\frac{a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 3.7505355971518835 \cdot 10^{302}:\\
\;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \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 (((((double) (((double) (a * c)) + ((double) (b * d)))) / ((double) (((double) (c * c)) + ((double) (d * d))))) <= -inf.0)) {
VAR = (a / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))));
} else {
double VAR_1;
if (((((double) (((double) (a * c)) + ((double) (b * d)))) / ((double) (((double) (c * c)) + ((double) (d * d))))) <= 3.7505355971518835e+302)) {
VAR_1 = ((double) ((1.0 / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))) * (((double) (((double) (a * c)) + ((double) (b * d)))) / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))))));
} else {
VAR_1 = (b / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 27.0 |
|---|---|
| Target | 0.5 |
| Herbie | 25.6 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < -inf.0Initial program 64.0
rmApplied add-sqr-sqrt64.0
Applied associate-/r*64.0
Taylor expanded around inf 51.9
if -inf.0 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.7505355971518835e302Initial program 12.0
rmApplied add-sqr-sqrt12.0
Applied *-un-lft-identity12.0
Applied times-frac12.0
if 3.7505355971518835e302 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.8
rmApplied add-sqr-sqrt63.8
Applied associate-/r*63.8
Taylor expanded around 0 60.2
Final simplification25.6
herbie shell --seed 2020182
(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))))