\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;y \le -9.23858159281642922 \cdot 10^{149}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \le -4.2522977642395074 \cdot 10^{-161}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{elif}\;y \le 8.2160851034417232 \cdot 10^{-160}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\end{array}double code(double x, double y) {
return (((x - y) * (x + y)) / ((x * x) + (y * y)));
}
double code(double x, double y) {
double temp;
if ((y <= -9.23858159281643e+149)) {
temp = -1.0;
} else {
double temp_1;
if ((y <= -4.2522977642395074e-161)) {
temp_1 = (((x - y) * (x + y)) / ((x * x) + (y * y)));
} else {
double temp_2;
if ((y <= 8.216085103441723e-160)) {
temp_2 = 1.0;
} else {
temp_2 = (((x - y) * (x + y)) / ((x * x) + (y * y)));
}
temp_1 = temp_2;
}
temp = temp_1;
}
return temp;
}




Bits error versus x




Bits error versus y
Results
| Original | 20.2 |
|---|---|
| Target | 0.1 |
| Herbie | 5.3 |
if y < -9.23858159281643e+149Initial program 62.4
Taylor expanded around 0 0
if -9.23858159281643e+149 < y < -4.2522977642395074e-161 or 8.216085103441723e-160 < y Initial program 0.0
if -4.2522977642395074e-161 < y < 8.216085103441723e-160Initial program 29.4
Taylor expanded around inf 16.2
Final simplification5.3
herbie shell --seed 2020066
(FPCore (x y)
:name "Kahan p9 Example"
:precision binary64
:pre (and (< 0.0 x 1) (< y 1))
:herbie-target
(if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))