\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;y \leq -1.2370463069395253 \cdot 10^{-39}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq -3.460569152566315 \cdot 10^{-162}:\\
\;\;\;\;\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}\\
\mathbf{elif}\;y \leq 9.138373226188112 \cdot 10^{-202}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.0362297196073818 \cdot 10^{-162}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}\\
\end{array}double code(double x, double y) {
return (((double) (((double) (x - y)) * ((double) (x + y)))) / ((double) (((double) (x * x)) + ((double) (y * y)))));
}
double code(double x, double y) {
double VAR;
if ((y <= -1.2370463069395253e-39)) {
VAR = -1.0;
} else {
double VAR_1;
if ((y <= -3.460569152566315e-162)) {
VAR_1 = (((double) (x - y)) / (((double) (((double) (x * x)) + ((double) (y * y)))) / ((double) (y + x))));
} else {
double VAR_2;
if ((y <= 9.138373226188112e-202)) {
VAR_2 = 1.0;
} else {
double VAR_3;
if ((y <= 1.0362297196073818e-162)) {
VAR_3 = -1.0;
} else {
VAR_3 = (((double) (x - y)) / (((double) (((double) (x * x)) + ((double) (y * y)))) / ((double) (y + x))));
}
VAR_2 = VAR_3;
}
VAR_1 = VAR_2;
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x




Bits error versus y
Results
| Original | 19.9 |
|---|---|
| Target | 0.0 |
| Herbie | 5.7 |
if y < -1.23704630693952534e-39 or 9.13837322618811221e-202 < y < 1.03622971960738184e-162Initial program 28.7
Taylor expanded around 0 3.9
if -1.23704630693952534e-39 < y < -3.46056915256631509e-162 or 1.03622971960738184e-162 < y Initial program 0.1
rmApplied associate-/l*0.8
if -3.46056915256631509e-162 < y < 9.13837322618811221e-202Initial program 28.9
Taylor expanded around inf 13.6
Final simplification5.7
herbie shell --seed 2020196
(FPCore (x y)
:name "Kahan p9 Example"
:precision binary64
:pre (and (< 0.0 x 1.0) (< y 1.0))
:herbie-target
(if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))