\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\begin{array}{l}
\mathbf{if}\;z \leq 1.1159320986222001 \cdot 10^{-41}:\\
\;\;\;\;-x\\
\mathbf{elif}\;z \leq 31844652.308985993:\\
\;\;\;\;\sqrt{z \cdot z + x \cdot x}\\
\mathbf{elif}\;z \leq 1.999825415585347 \cdot 10^{+59}:\\
\;\;\;\;-x\\
\mathbf{elif}\;z \leq 1.5165136515313232 \cdot 10^{+91}:\\
\;\;\;\;\sqrt{z \cdot z + x \cdot x}\\
\mathbf{elif}\;z \leq 3.4920392089304095 \cdot 10^{+104}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
:precision binary64
(if (<= z 1.1159320986222001e-41)
(- x)
(if (<= z 31844652.308985993)
(sqrt (+ (* z z) (* x x)))
(if (<= z 1.999825415585347e+59)
(- x)
(if (<= z 1.5165136515313232e+91)
(sqrt (+ (* z z) (* x x)))
(if (<= z 3.4920392089304095e+104) (- x) z))))))double code(double x, double y, double z) {
return sqrt(((x * x) + (y * y)) + (z * z));
}
double code(double x, double y, double z) {
double tmp;
if (z <= 1.1159320986222001e-41) {
tmp = -x;
} else if (z <= 31844652.308985993) {
tmp = sqrt((z * z) + (x * x));
} else if (z <= 1.999825415585347e+59) {
tmp = -x;
} else if (z <= 1.5165136515313232e+91) {
tmp = sqrt((z * z) + (x * x));
} else if (z <= 3.4920392089304095e+104) {
tmp = -x;
} else {
tmp = z;
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 37.8 |
|---|---|
| Target | 19.8 |
| Herbie | 13.1 |
if z < 1.11593209862220009e-41 or 31844652.308985993 < z < 1.99982541558534707e59 or 1.51651365153132315e91 < z < 3.49203920893040948e104Initial program 27.8
Taylor expanded around -inf 13.0
if 1.11593209862220009e-41 < z < 31844652.308985993 or 1.99982541558534707e59 < z < 1.51651365153132315e91Initial program 19.8
Taylor expanded around 0 20.2
Simplified20.2
if 3.49203920893040948e104 < z Initial program 54.5
Taylor expanded around inf 11.0
Final simplification13.1
herbie shell --seed 2021015
(FPCore (x y z)
:name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
:precision binary64
:herbie-target
(if (< z -6.396479394109776e+136) (- z) (if (< z 7.320293694404182e+117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))
(sqrt (+ (+ (* x x) (* y y)) (* z z))))