\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\begin{array}{l}
\mathbf{if}\;z \leq -2.1775431588860127 \cdot 10^{+114}:\\
\;\;\;\;-z\\
\mathbf{elif}\;z \leq -9.91481798046696 \cdot 10^{-160}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\
\mathbf{elif}\;z \leq -1.1752862576324589 \cdot 10^{-195}:\\
\;\;\;\;-x\\
\mathbf{elif}\;z \leq -4.738824455578195 \cdot 10^{-226}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\
\mathbf{elif}\;z \leq -5.606683175932588 \cdot 10^{-254}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.927780121112873 \cdot 10^{+149}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\
\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 -2.1775431588860127e+114)
(- z)
(if (<= z -9.91481798046696e-160)
(sqrt (+ (+ (* x x) (* y y)) (* z z)))
(if (<= z -1.1752862576324589e-195)
(- x)
(if (<= z -4.738824455578195e-226)
(sqrt (+ (+ (* x x) (* y y)) (* z z)))
(if (<= z -5.606683175932588e-254)
x
(if (<= z 6.927780121112873e+149)
(sqrt (+ (+ (* x x) (* y y)) (* z z)))
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 <= -2.1775431588860127e+114) {
tmp = -z;
} else if (z <= -9.91481798046696e-160) {
tmp = sqrt(((x * x) + (y * y)) + (z * z));
} else if (z <= -1.1752862576324589e-195) {
tmp = -x;
} else if (z <= -4.738824455578195e-226) {
tmp = sqrt(((x * x) + (y * y)) + (z * z));
} else if (z <= -5.606683175932588e-254) {
tmp = x;
} else if (z <= 6.927780121112873e+149) {
tmp = sqrt(((x * x) + (y * y)) + (z * z));
} else {
tmp = z;
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 38.0 |
|---|---|
| Target | 25.5 |
| Herbie | 26.2 |
if z < -2.1775431588860127e114Initial program 57.5
Taylor expanded around -inf 18.5
if -2.1775431588860127e114 < z < -9.9148179804669601e-160 or -1.175286257632459e-195 < z < -4.7388244555781947e-226 or -5.60668317593258815e-254 < z < 6.9277801211128734e149Initial program 28.6
if -9.9148179804669601e-160 < z < -1.175286257632459e-195Initial program 31.9
Taylor expanded around -inf 46.6
Simplified46.6
if -4.7388244555781947e-226 < z < -5.60668317593258815e-254Initial program 33.7
Taylor expanded around inf 45.4
if 6.9277801211128734e149 < z Initial program 62.7
Taylor expanded around inf 15.3
Final simplification26.2
herbie shell --seed 2021024
(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))))