// Wild Magic Source Code // David Eberly // http://www.geometrictools.com // Copyright (c) 1998-2007 // // This library is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation; either version 2.1 of the License, or (at // your option) any later version. The license is available for reading at // either of the locations: // http://www.gnu.org/copyleft/lgpl.html // http://www.geometrictools.com/License/WildMagicLicense.pdf // The license applies to versions 0 through 4 of Wild Magic. // // Version: 4.0.0 (2006/06/28) #include "Wm4FoundationPCH.h" #include "Wm4Math.h" namespace Wm4 { template<> const float Math::EPSILON = FLT_EPSILON; template<> const float Math::ZERO_TOLERANCE = 1e-06f; template<> const float Math::MAX_REAL = FLT_MAX; template<> const float Math::PI = (float)(4.0*atan(1.0)); template<> const float Math::TWO_PI = 2.0f*Math::PI; template<> const float Math::HALF_PI = 0.5f*Math::PI; template<> const float Math::INV_PI = 1.0f/Math::PI; template<> const float Math::INV_TWO_PI = 1.0f/Math::TWO_PI; template<> const float Math::DEG_TO_RAD = Math::PI/180.0f; template<> const float Math::RAD_TO_DEG = 180.0f/Math::PI; template<> const float Math::LN_2 = Math::Log(2.0f); template<> const float Math::LN_10 = Math::Log(10.0f); template<> const float Math::INV_LN_2 = 1.0f/Math::LN_2; template<> const float Math::INV_LN_10 = 1.0f/Math::LN_10; template<> const double Math::EPSILON = DBL_EPSILON; template<> const double Math::ZERO_TOLERANCE = 1e-08; template<> const double Math::MAX_REAL = DBL_MAX; template<> const double Math::PI = 4.0*atan(1.0); template<> const double Math::TWO_PI = 2.0*Math::PI; template<> const double Math::HALF_PI = 0.5*Math::PI; template<> const double Math::INV_PI = 1.0/Math::PI; template<> const double Math::INV_TWO_PI = 1.0/Math::TWO_PI; template<> const double Math::DEG_TO_RAD = Math::PI/180.0; template<> const double Math::RAD_TO_DEG = 180.0/Math::PI; template<> const double Math::LN_2 = Math::Log(2.0); template<> const double Math::LN_10 = Math::Log(10.0); template<> const double Math::INV_LN_2 = 1.0/Math::LN_2; template<> const double Math::INV_LN_10 = 1.0/Math::LN_10; //---------------------------------------------------------------------------- //Does not compile with gcc 4.1.2 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) template <> float Math::FastInvSqrt (float fValue) { float fHalf = 0.5f*fValue; int i = *(int*)&fValue; i = 0x5f3759df - (i >> 1); fValue = *(float*)&i; fValue = fValue*(1.5f - fHalf*fValue*fValue); return fValue; } //---------------------------------------------------------------------------- template <> double Math::FastInvSqrt (double dValue) { double dHalf = 0.5*dValue; Integer64 i = *(Integer64*)&dValue; #if defined(WM4_USING_VC70) || defined(WM4_USING_VC6) i = 0x5fe6ec85e7de30da - (i >> 1); #else i = 0x5fe6ec85e7de30daLL - (i >> 1); #endif dValue = *(double*)&i; dValue = dValue*(1.5 - dHalf*dValue*dValue); return dValue; } #endif //---------------------------------------------------------------------------- }