00001 // Wild Magic Source Code 00002 // David Eberly 00003 // http://www.geometrictools.com 00004 // Copyright (c) 1998-2007 00005 // 00006 // This library is free software; you can redistribute it and/or modify it 00007 // under the terms of the GNU Lesser General Public License as published by 00008 // the Free Software Foundation; either version 2.1 of the License, or (at 00009 // your option) any later version. The license is available for reading at 00010 // either of the locations: 00011 // http://www.gnu.org/copyleft/lgpl.html 00012 // http://www.geometrictools.com/License/WildMagicLicense.pdf 00013 // The license applies to versions 0 through 4 of Wild Magic. 00014 // 00015 // Version: 4.0.0 (2006/06/28) 00016 00017 #include "Wm4FoundationPCH.h" 00018 #include "Wm4Math.h" 00019 using namespace Wm4; 00020 00021 template<> const float Math<float>::EPSILON = FLT_EPSILON; 00022 template<> const float Math<float>::ZERO_TOLERANCE = 1e-06f; 00023 template<> const float Math<float>::MAX_REAL = FLT_MAX; 00024 template<> const float Math<float>::PI = (float)(4.0*atan(1.0)); 00025 template<> const float Math<float>::TWO_PI = 2.0f*Math<float>::PI; 00026 template<> const float Math<float>::HALF_PI = 0.5f*Math<float>::PI; 00027 template<> const float Math<float>::INV_PI = 1.0f/Math<float>::PI; 00028 template<> const float Math<float>::INV_TWO_PI = 1.0f/Math<float>::TWO_PI; 00029 template<> const float Math<float>::DEG_TO_RAD = Math<float>::PI/180.0f; 00030 template<> const float Math<float>::RAD_TO_DEG = 180.0f/Math<float>::PI; 00031 template<> const float Math<float>::LN_2 = Math<float>::Log(2.0f); 00032 template<> const float Math<float>::LN_10 = Math<float>::Log(10.0f); 00033 template<> const float Math<float>::INV_LN_2 = 1.0f/Math<float>::LN_2; 00034 template<> const float Math<float>::INV_LN_10 = 1.0f/Math<float>::LN_10; 00035 00036 template<> const double Math<double>::EPSILON = DBL_EPSILON; 00037 template<> const double Math<double>::ZERO_TOLERANCE = 1e-08; 00038 template<> const double Math<double>::MAX_REAL = DBL_MAX; 00039 template<> const double Math<double>::PI = 4.0*atan(1.0); 00040 template<> const double Math<double>::TWO_PI = 2.0*Math<double>::PI; 00041 template<> const double Math<double>::HALF_PI = 0.5*Math<double>::PI; 00042 template<> const double Math<double>::INV_PI = 1.0/Math<double>::PI; 00043 template<> const double Math<double>::INV_TWO_PI = 1.0/Math<double>::TWO_PI; 00044 template<> const double Math<double>::DEG_TO_RAD = Math<double>::PI/180.0; 00045 template<> const double Math<double>::RAD_TO_DEG = 180.0/Math<double>::PI; 00046 template<> const double Math<double>::LN_2 = Math<double>::Log(2.0); 00047 template<> const double Math<double>::LN_10 = Math<double>::Log(10.0); 00048 template<> const double Math<double>::INV_LN_2 = 1.0/Math<double>::LN_2; 00049 template<> const double Math<double>::INV_LN_10 = 1.0/Math<double>::LN_10; 00050 00051 namespace Wm4 { 00052 //---------------------------------------------------------------------------- 00053 //Does not compile with gcc 4.1.2 00054 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 00055 template <> 00056 float Math<float>::FastInvSqrt (float fValue) 00057 { 00058 float fHalf = 0.5f*fValue; 00059 int i = *(int*)&fValue; 00060 i = 0x5f3759df - (i >> 1); 00061 fValue = *(float*)&i; 00062 fValue = fValue*(1.5f - fHalf*fValue*fValue); 00063 return fValue; 00064 } 00065 //---------------------------------------------------------------------------- 00066 template <> 00067 double Math<double>::FastInvSqrt (double dValue) 00068 { 00069 double dHalf = 0.5*dValue; 00070 Integer64 i = *(Integer64*)&dValue; 00071 #if defined(WM4_USING_VC70) || defined(WM4_USING_VC6) 00072 i = 0x5fe6ec85e7de30da - (i >> 1); 00073 #else 00074 i = 0x5fe6ec85e7de30daLL - (i >> 1); 00075 #endif 00076 dValue = *(double*)&i; 00077 dValue = dValue*(1.5 - dHalf*dValue*dValue); 00078 return dValue; 00079 } 00080 #endif 00081 //---------------------------------------------------------------------------- 00082 }