\sqrt{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;y \leq -1.8899720103254926 \cdot 10^{+146}:\\
\;\;\;\;\left|x\right|\\
\mathbf{elif}\;y \leq -2.454304521609729 \cdot 10^{-75}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\
\mathbf{elif}\;y \leq 8.447014685477577 \cdot 10^{-160}:\\
\;\;\;\;\left|x\right|\\
\mathbf{elif}\;y \leq 1.6336242095797044 \cdot 10^{-143}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.3066676791772896 \cdot 10^{-35}:\\
\;\;\;\;\left|x\right|\\
\mathbf{elif}\;y \leq 4.248125126133587 \cdot 10^{+95}:\\
\;\;\;\;\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 -1.8899720103254926e+146)
(fabs x)
(if (<= y -2.454304521609729e-75)
(sqrt (+ (* x x) (* y y)))
(if (<= y 8.447014685477577e-160)
(fabs x)
(if (<= y 1.6336242095797044e-143)
y
(if (<= y 1.3066676791772896e-35)
(fabs x)
(if (<= y 4.248125126133587e+95) (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 <= -1.8899720103254926e+146) {
tmp = fabs(x);
} else if (y <= -2.454304521609729e-75) {
tmp = sqrt((x * x) + (y * y));
} else if (y <= 8.447014685477577e-160) {
tmp = fabs(x);
} else if (y <= 1.6336242095797044e-143) {
tmp = y;
} else if (y <= 1.3066676791772896e-35) {
tmp = fabs(x);
} else if (y <= 4.248125126133587e+95) {
tmp = sqrt((x * x) + (y * y));
} else {
tmp = y;
}
return tmp;
}




Bits error versus x




Bits error versus y
Results
| Original | 31.6 |
|---|---|
| Target | 17.1 |
| Herbie | 18.7 |
if y < -1.88997201032549258e146 or -2.4543045216097289e-75 < y < 8.44701468547757748e-160 or 1.6336242095797044e-143 < y < 1.3066676791772896e-35Initial program 34.3
Taylor expanded around 0 40.6
Simplified40.6
rmApplied rem-sqrt-square_binary64_1782322.1
if -1.88997201032549258e146 < y < -2.4543045216097289e-75 or 1.3066676791772896e-35 < y < 4.24812512613358684e95Initial program 15.8
if 8.44701468547757748e-160 < y < 1.6336242095797044e-143 or 4.24812512613358684e95 < y Initial program 48.1
Taylor expanded around 0 13.6
Final simplification18.7
herbie shell --seed 2020344
(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))))