\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} = -\infty:\\
\;\;\;\;\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 2.7315775484124213 \cdot 10^{281}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}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 VAR;
if (((((a * c) + (b * d)) / ((c * c) + (d * d))) <= -inf.0)) {
VAR = (a / sqrt(((c * c) + (d * d))));
} else {
double VAR_1;
if (((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2.7315775484124213e+281)) {
VAR_1 = ((((a * c) + (b * d)) / sqrt(((c * c) + (d * d)))) / sqrt(((c * c) + (d * d))));
} else {
VAR_1 = ((-1.0 * a) / sqrt(((c * c) + (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 | 26.2 |
|---|---|
| Target | 0.5 |
| Herbie | 25.0 |
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 52.0
if -inf.0 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 2.7315775484124213e+281Initial program 11.7
rmApplied add-sqr-sqrt11.7
Applied associate-/r*11.6
if 2.7315775484124213e+281 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 62.6
rmApplied add-sqr-sqrt62.6
Applied associate-/r*62.6
Taylor expanded around -inf 60.0
Final simplification25.0
herbie shell --seed 2020091
(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))))