\sqrt{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;x \leq -1.6585338134613207 \cdot 10^{+142}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 1.0618359535513641 \cdot 10^{+80}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}(FPCore (x y) :precision binary64 (sqrt (+ (* x x) (* y y))))
(FPCore (x y) :precision binary64 (if (<= x -1.6585338134613207e+142) (- x) (if (<= x 1.0618359535513641e+80) (sqrt (+ (* x x) (* y y))) x)))
double code(double x, double y) {
return sqrt((x * x) + (y * y));
}
double code(double x, double y) {
double tmp;
if (x <= -1.6585338134613207e+142) {
tmp = -x;
} else if (x <= 1.0618359535513641e+80) {
tmp = sqrt((x * x) + (y * y));
} else {
tmp = x;
}
return tmp;
}




Bits error versus x




Bits error versus y
Results
| Original | 31.7 |
|---|---|
| Target | 17.7 |
| Herbie | 17.7 |
if x < -1.6585338134613207e142Initial program 60.8
Taylor expanded around -inf 7.9
Simplified7.9
if -1.6585338134613207e142 < x < 1.0618359535513641e80Initial program 21.6
if 1.0618359535513641e80 < x Initial program 47.0
Taylor expanded around inf 11.1
Final simplification17.7
herbie shell --seed 2020220
(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))))