\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\begin{array}{l}
\mathbf{if}\;\left(x \cdot x + y \cdot y\right) + z \cdot z \leq 3.824751598715583 \cdot 10^{+307}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\left|z\right|\\
\end{array}(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z) :precision binary64 (if (<= (+ (+ (* x x) (* y y)) (* z z)) 3.824751598715583e+307) (sqrt (+ (+ (* x x) (* y y)) (* z z))) (fabs 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 ((((x * x) + (y * y)) + (z * z)) <= 3.824751598715583e+307) {
tmp = sqrt(((x * x) + (y * y)) + (z * z));
} else {
tmp = fabs(z);
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 38.1 |
|---|---|
| Target | 25.6 |
| Herbie | 24.9 |
if (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) < 3.82475159871558313e307Initial program 2.0
if 3.82475159871558313e307 < (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) Initial program 63.9
Taylor expanded around 0 62.7
rmApplied *-un-lft-identity_binary6462.7
Applied sqrt-prod_binary6462.7
Simplified62.7
Simplified41.3
Final simplification24.9
herbie shell --seed 2020288
(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))))