add btVector3::safeNorm to avoid/workaround certain clang/g++ issue or returning -INF

when taking sqrtf(0.0000000000000000000000000000000000000108333558)
This commit is contained in:
Erwin Coumans
2016-09-25 23:13:23 -07:00
parent c05784ea88
commit 6563c9c821
3 changed files with 16 additions and 6 deletions

View File

@@ -267,10 +267,20 @@ public:
/**@brief Return the norm (length) of the vector */
SIMD_FORCE_INLINE btScalar norm() const
{
{
return length();
}
/**@brief Return the norm (length) of the vector */
SIMD_FORCE_INLINE btScalar safeNorm() const
{
btScalar d = length2();
//workaround for some clang/gcc issue of sqrtf(tiny number) = -INF
if (d>SIMD_EPSILON)
return btSqrt(d);
return btScalar(0);
}
/**@brief Return the distance squared between the ends of this and another vector
* This is symantically treating the vector like a point */
SIMD_FORCE_INLINE btScalar distance2(const btVector3& v) const;