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




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 37.9 |
|---|---|
| Target | 25.1 |
| Herbie | 33.9 |
if x < -9.2507672703400312e-298 or 5.5922795307274933e-180 < x < 4.259597241345245e42Initial program 35.4
if -9.2507672703400312e-298 < x < 5.5922795307274933e-180Initial program 33.1
Taylor expanded around 0 47.6
Simplified47.6
Taylor expanded around 0 47.1
Simplified47.1
if 4.259597241345245e42 < x Initial program 48.0
Taylor expanded around 0 49.4
Simplified49.4
Taylor expanded around 0 22.6
Final simplification33.9
herbie shell --seed 2020344
(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))))