\sqrt{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;x \leq -1.8823818060423687 \cdot 10^{+93}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -8.295868111085673 \cdot 10^{-165}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\
\mathbf{elif}\;x \leq -1.7085030248267635 \cdot 10^{-189}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}(FPCore (x y) :precision binary64 (sqrt (+ (* x x) (* y y))))
(FPCore (x y)
:precision binary64
(if (<= x -1.8823818060423687e+93)
(- x)
(if (<= x -8.295868111085673e-165)
(sqrt (+ (* x x) (* y y)))
(if (<= x -1.7085030248267635e-189) (- x) y))))double code(double x, double y) {
return sqrt((x * x) + (y * y));
}
double code(double x, double y) {
double tmp;
if (x <= -1.8823818060423687e+93) {
tmp = -x;
} else if (x <= -8.295868111085673e-165) {
tmp = sqrt((x * x) + (y * y));
} else if (x <= -1.7085030248267635e-189) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}




Bits error versus x




Bits error versus y
Results
| Original | 31.2 |
|---|---|
| Target | 17.5 |
| Herbie | 7.8 |
if x < -1.88238180604236865e93 or -8.29586811108567327e-165 < x < -1.70850302482676351e-189Initial program 48.3
Taylor expanded around -inf 8.6
Simplified8.6
if -1.88238180604236865e93 < x < -8.29586811108567327e-165Initial program 11.7
if -1.70850302482676351e-189 < x Initial program 31.5
Taylor expanded around 0 3.9
Final simplification7.8
herbie shell --seed 2021058
(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))))