MobilityDB
1.0
|
◆ hypot3d()
Determine the 3D hypotenuse. If required, x, y, and z are swapped to make x the larger number. The traditional formula of x^2+y^2+z^2 is rearranged to factor x outside the sqrt. This allows computation of the hypotenuse for significantly larger values, and with a higher precision than when using the naive formula. In particular, this cannot overflow unless the final result would be out-of-range. sqrt( x^2 + y^2 + z^2 ) = sqrt( x^2( 1 + y^2/x^2 + z^2/x^2) ) = x * sqrt( 1 + y^2/x^2 + z^2/x^2) = x * sqrt( 1 + y/x * y/x + z/x * z/x) |