constants.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00013 #ifndef cml_constants_h
00014 #define cml_constants_h
00015
00016 #include <cmath>
00017
00018 #if !defined(M_PI)
00019 #define M_PI 3.14159265358979323846264338327950288
00020 #endif
00021
00022 #if !defined(M_SQRT2)
00023 #define M_SQRT2 1.41421356237309504880168872420969808
00024 #endif
00025
00026 #if !defined(M_E)
00027 #define M_E 2.71828182845904523536028747135266250
00028 #endif
00029
00030 namespace cml {
00031
00032 #if 1
00033
00038 template<typename Float>
00039 struct constants {
00040 static Float pi() { return Float(M_PI); }
00041 static Float two_pi() { return Float(2.*M_PI); }
00042 static Float inv_pi() { return Float(1./M_PI); }
00043 static Float inv_two_pi() { return Float(1./(2.*M_PI)); }
00044 static Float pi_over_2() { return Float(M_PI/2.); }
00045 static Float pi_over_4() { return Float(M_PI/4.); }
00046 static Float deg_per_rad() { return Float(180./M_PI); }
00047 static Float rad_per_deg() { return Float(M_PI/180.); }
00048
00049 static Float sqrt_2() { return Float(M_SQRT2); }
00050 static Float sqrt_3() { return Float(1.732050807568877293527446341505); }
00051 static Float sqrt_5() { return Float(2.236067977499789696409173668731); }
00052 static Float sqrt_6() { return Float(2.449489742783178098197284074705); }
00053
00054 static Float e() { return Float(M_E); }
00055 };
00056
00057 #else
00058
00059
00060
00061
00062
00063
00068 template<typename Float>
00069 struct constants {
00070 static const Float pi = M_PI;
00071 static const Float two_pi = 2.*M_PI;
00072 static const Float inv_pi = 1./M_PI;
00073 static const Float inv_two_pi = 1./(2.*M_PI);
00074 static const Float pi_over_2 = M_PI/2.;
00075 static const Float pi_over_4 = M_PI/4.;
00076 static const Float deg_per_rad = 180./M_PI;
00077 static const Float rad_per_deg = M_PI/180.;
00078 static const Float sqrt_2 = M_SQRT2;
00079 static const Float sqrt_3 = 1.73205080756887729352744634150587237;
00080 static const Float sqrt_5 = 2.23606797749978969640917366873127624;
00081 static const Float sqrt_6 = 2.44948974278317809819728407470589139;
00082 static const Float e = M_E;
00083 };
00084
00085 #endif
00086
00087 }
00088
00089 #endif