\sqrt{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;y \leq -4.1162129695124836 \cdot 10^{+151}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq -2.1964806768619867 \cdot 10^{-223}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\
\mathbf{elif}\;y \leq 2.11287353661743 \cdot 10^{-238}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 7.549554504255097 \cdot 10^{+118}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}(FPCore (x y) :precision binary64 (sqrt (+ (* x x) (* y y))))
(FPCore (x y)
:precision binary64
(if (<= y -4.1162129695124836e+151)
(- y)
(if (<= y -2.1964806768619867e-223)
(sqrt (+ (* x x) (* y y)))
(if (<= y 2.11287353661743e-238)
(- x)
(if (<= y 7.549554504255097e+118) (sqrt (+ (* x x) (* y y))) y)))))double code(double x, double y) {
return sqrt((x * x) + (y * y));
}
double code(double x, double y) {
double tmp;
if (y <= -4.1162129695124836e+151) {
tmp = -y;
} else if (y <= -2.1964806768619867e-223) {
tmp = sqrt((x * x) + (y * y));
} else if (y <= 2.11287353661743e-238) {
tmp = -x;
} else if (y <= 7.549554504255097e+118) {
tmp = sqrt((x * x) + (y * y));
} else {
tmp = y;
}
return tmp;
}









Bits error versus x









Bits error versus y
Results
| Original | 31.1 |
|---|---|
| Target | 17.2 |
| Herbie | 17.2 |
| Alternative 1 | |
|---|---|
| Error | 25.7 |
| Cost | 1027 |
| Alternative 2 | |
|---|---|
| Error | 26.5 |
| Cost | 706 |
| Alternative 3 | |
|---|---|
| Error | 36.8 |
| Cost | 1027 |
| Alternative 4 | |
|---|---|
| Error | 46.0 |
| Cost | 385 |
| Alternative 5 | |
|---|---|
| Error | 60.5 |
| Cost | 64 |

if y < -4.11621296951248365e151Initial program 63.7
Taylor expanded around -inf 7.0
Simplified7.0
Simplified7.0
if -4.11621296951248365e151 < y < -2.1964806768619867e-223 or 2.1128735366174298e-238 < y < 7.549554504255097e118Initial program 18.1
Simplified18.1
if -2.1964806768619867e-223 < y < 2.1128735366174298e-238Initial program 30.4
Taylor expanded around -inf 32.4
Simplified32.4
Simplified32.4
if 7.549554504255097e118 < y Initial program 54.8
Taylor expanded around 0 9.5
Simplified9.5
Final simplification17.2
herbie shell --seed 2021044
(FPCore (x y)
:name "Data.Octree.Internal:octantDistance from Octree-0.5.4.2"
:precision binary64
:herbie-target
(if (< x -1.1236950826599826e+145) (- x) (if (< x 1.116557621183362e+93) (sqrt (+ (* x x) (* y y))) x))
(sqrt (+ (* x x) (* y y))))