\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -1.9497673481821607 \cdot 10^{115} \lor \neg \left(d \le 6.67079582011057737 \cdot 10^{138}\right):\\
\;\;\;\;\frac{-1 \cdot {b}^{2}}{a \cdot c - b \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{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 (((d <= -1.9497673481821607e+115) || !(d <= 6.670795820110577e+138))) {
VAR = ((-1.0 * pow(b, 2.0)) / ((a * c) - (b * d)));
} else {
VAR = (((a * c) + (b * d)) / ((c * c) + (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.4 |
| Herbie | 23.9 |
if d < -1.9497673481821607e+115 or 6.670795820110577e+138 < d Initial program 41.7
rmApplied clear-num41.8
rmApplied flip-+48.6
Applied associate-/r/48.7
Applied associate-/r*48.7
Simplified48.6
Taylor expanded around 0 34.7
if -1.9497673481821607e+115 < d < 6.670795820110577e+138Initial program 19.0
Final simplification23.9
herbie shell --seed 2020071 +o rules:numerics
(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))))