comparison engine/core/util/math/fife_math.h @ 623:684e5537eef7

* Moving the math constants to the FIFE namespace * Added swig interfaces for the math constants
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 01 Oct 2010 16:26:22 +0000
parents 356634098bd9
children 07b1cf8e92b5
comparison
equal deleted inserted replaced
622:c0c3f64bfc2d 623:684e5537eef7
32 // FIFE includes 32 // FIFE includes
33 // These includes are split up in two parts, separated by one empty line 33 // These includes are split up in two parts, separated by one empty line
34 // First block: files included from the FIFE root src directory 34 // First block: files included from the FIFE root src directory
35 // Second block: files included from the same folder 35 // Second block: files included from the same folder
36 36
37 #ifndef ABS
38 #define ABS(x) ((x)<0?-(x):(x))
39
40 #endif
37 41
38 // Sort out the missing round function in MSVC: 42 // Sort out the missing round function in MSVC:
39 #if defined( WIN32 ) && defined( _MSC_VER ) 43 #if defined( WIN32 ) && defined( _MSC_VER )
40 inline double round(const double x) { 44 inline double round(const double x) {
41 return x < 0.0 ? ceil(x - 0.5) : floor(x + 0.5); 45 return x < 0.0 ? ceil(x - 0.5) : floor(x + 0.5);
42 } 46 }
43 #endif 47 #endif
44 48
45 #ifndef ABS 49 namespace FIFE {
46 #define ABS(x) ((x)<0?-(x):(x))
47 50
48 #endif 51 static const float FLT_ZERO_TOLERANCE = 1e-06f;
52 static const float FLT_PI = 4.0f*std::atan(1.0f);
53 static const float FLT_TWO_PI = 2.0f*FLT_PI;
54 static const float FLT_HALF_PI = 0.5f*FLT_PI;
55 static const float FLT_INVERSE_PI = 1.0f/FLT_PI;
56 static const float FLT_INVERSE_TWO_PI = 1.0f/FLT_TWO_PI;
57 static const float FLT_DEG_TO_RAD = FLT_PI/180.0f;
58 static const float FLT_RAD_TO_DEG = 180.0f/FLT_PI;
59 static const float FLT_LOG_2 = std::log(2.0f);
60 static const float FLT_LOG_10 = std::log(10.0f);
61 static const float FLT_INV_LOG_2 = 1.0f/std::log(2.0f);
62 static const float FLT_INV_LOG_10 = 1.0f/std::log(10.0f);
49 63
50 static const float FLT_ZERO_TOLERANCE = 1e-06f; 64 static const double DBL_ZERO_TOLERANCE = 1e-08;
51 static const float FLT_PI = 4.0f*std::atan(1.0f); 65 static const double DBL_PI = 4.0*std::atan(1.0f);
52 static const float FLT_TWO_PI = 2.0f*FLT_PI; 66 static const double DBL_TWO_PI = 2.0*DBL_PI;
53 static const float FLT_HALF_PI = 0.5f*FLT_PI; 67 static const double DBL_HALF_PI = 0.5*DBL_PI;
54 static const float FLT_INVERSE_PI = 1.0f/FLT_PI; 68 static const double DBL_INVERSE_PI = 1.0/DBL_PI;
55 static const float FLT_INVERSE_TWO_PI = 1.0f/FLT_TWO_PI; 69 static const double DBL_INVERSE_TWO_PI = 1.0/DBL_TWO_PI;
56 static const float FLT_DEG_TO_RAD = FLT_PI/180.0f; 70 static const double DBL_DEG_TO_RAD = DBL_PI/180.0;
57 static const float FLT_RAD_TO_DEG = 180.0f/FLT_PI; 71 static const double DBL_RAD_TO_DEG = 180.0/DBL_PI;
58 static const float FLT_LOG_2 = std::log(2.0f); 72 static const double DBL_LOG_2 = std::log(2.0f);
59 static const float FLT_LOG_10 = std::log(10.0f); 73 static const double DBL_LOG_10 = std::log(10.0f);
60 static const float FLT_INV_LOG_2 = 1.0f/std::log(2.0f); 74 static const double DBL_INV_LOG_2 = 1.0/std::log(2.0f);
61 static const float FLT_INV_LOG_10 = 1.0f/std::log(10.0f); 75 static const double DBL_INV_LOG_10 = 1.0/std::log(10.0f);
62 76
63 static const double DBL_ZERO_TOLERANCE = 1e-08; 77 inline unsigned nextPow2(unsigned x)
64 static const double DBL_PI = 4.0*std::atan(1.0f); 78 {
65 static const double DBL_TWO_PI = 2.0*DBL_PI; 79 --x;
66 static const double DBL_HALF_PI = 0.5*DBL_PI; 80 x |= x >> 1;
67 static const double DBL_INVERSE_PI = 1.0/DBL_PI; 81 x |= x >> 2;
68 static const double DBL_INVERSE_TWO_PI = 1.0/DBL_TWO_PI; 82 x |= x >> 4;
69 static const double DBL_DEG_TO_RAD = DBL_PI/180.0; 83 x |= x >> 8;
70 static const double DBL_RAD_TO_DEG = 180.0/DBL_PI; 84 x |= x >> 16;
71 static const double DBL_LOG_2 = std::log(2.0f); 85 return ++x;
72 static const double DBL_LOG_10 = std::log(10.0f); 86 }
73 static const double DBL_INV_LOG_2 = 1.0/std::log(2.0f); 87 } //FIFE
74 static const double DBL_INV_LOG_10 = 1.0/std::log(10.0f);
75
76 inline unsigned nextPow2(unsigned x)
77 {
78 --x;
79 x |= x >> 1;
80 x |= x >> 2;
81 x |= x >> 4;
82 x |= x >> 8;
83 x |= x >> 16;
84 return ++x;
85 }
86
87 88
88 #endif // FIFE_UTIL_FIFE_MATH_H 89 #endif // FIFE_UTIL_FIFE_MATH_H