\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\begin{array}{l}
\mathbf{if}\;y \leq -1.3608159443905432 \cdot 10^{+154}:\\
\;\;\;\;-0.5 \cdot \left(\frac{z \cdot z}{y} + \frac{x \cdot x}{y}\right) - y\\
\mathbf{elif}\;y \leq 2.64775110294404 \cdot 10^{+108}:\\
\;\;\;\;\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}\\
\mathbf{else}:\\
\;\;\;\;y + \left(\frac{z \cdot z}{y} + \frac{x \cdot x}{y}\right) \cdot 0.5\\
\end{array}(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
:precision binary64
(if (<= y -1.3608159443905432e+154)
(- (* -0.5 (+ (/ (* z z) y) (/ (* x x) y))) y)
(if (<= y 2.64775110294404e+108)
(sqrt (+ (* z z) (+ (* x x) (* y y))))
(+ y (* (+ (/ (* z z) y) (/ (* x x) y)) 0.5)))))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 (y <= -1.3608159443905432e+154) {
tmp = (-0.5 * (((z * z) / y) + ((x * x) / y))) - y;
} else if (y <= 2.64775110294404e+108) {
tmp = sqrt((z * z) + ((x * x) + (y * y)));
} else {
tmp = y + ((((z * z) / y) + ((x * x) / y)) * 0.5);
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 37.6 |
|---|---|
| Target | 25.5 |
| Herbie | 28.0 |
if y < -1.36081594439054316e154Initial program 64.0
Taylor expanded around -inf 27.4
Simplified27.4
if -1.36081594439054316e154 < y < 2.64775110294404e108Initial program 28.3
if 2.64775110294404e108 < y Initial program 55.7
Taylor expanded around inf 27.3
Simplified27.3
Final simplification28.0
herbie shell --seed 2020339
(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))))