\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} \leq 6.971051725145218 \cdot 10^{+287}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\frac{\sqrt{c \cdot c + d \cdot d}}{a \cdot c + b \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\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))))) <= 6.971051725145218e+287)) {
VAR = ((1.0 / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))) / (((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))) / ((double) (((double) (a * c)) + ((double) (b * d))))));
} else {
VAR = (((double) -(a)) / ((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 | 27.0 |
|---|---|
| Target | 0.4 |
| Herbie | 26.4 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 6.9710517251452183e287Initial program 14.6
rmApplied clear-num14.8
rmApplied *-un-lft-identity14.8
Applied add-sqr-sqrt14.8
Applied times-frac14.8
Applied associate-/r*14.6
Simplified14.6
if 6.9710517251452183e287 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.0
rmApplied add-sqr-sqrt63.0
Applied associate-/r*63.0
Taylor expanded around -inf 60.3
Simplified60.3
Final simplification26.4
herbie shell --seed 2020196
(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))))