Gamma  0.9.5
Generic Synthesis Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
/Users/ljp/code/gamma/trunk/Gamma/Constants.h
00001 #ifndef GAMMA_CONSTANTS_H_INC
00002 #define GAMMA_CONSTANTS_H_INC
00003 
00004 /*  Gamma - Generic processing library
00005     See COPYRIGHT file for authors and license information
00006 
00007     File Description: 
00008     Definitions of numerical constants.
00009 */
00010 
00011 
00012 #include "Gamma/pstdint.h"
00013 
00014 namespace gam{
00015 
00016 #define CONST(N, vf, vd)\
00017     template <class T> struct N;\
00018     template<> struct N< float>{ operator uint32_t() const { return vf##UL; } };\
00019     template<> struct N<double>{ operator uint64_t() const { return vd##ULL; } };
00020 
00021     /*      sign +  expo +  frac =  total
00022     float   1        8      23      32
00023     double  1       11      52      64
00024     */
00025 
00026     CONST(MaskExpo, 0x7F800000, 0x7FF0000000000000) // IEEE-754 floating-point exponent bit mask
00027     CONST(MaskFrac, 0x007FFFFF, 0x000FFFFFFFFFFFFF) // IEEE-754 floating-point fraction bit mask
00028     CONST(MaskSign, 0x80000000, 0x8000000000000000) // IEEE-754 floating-point sign bit mask
00029     CONST(Expo1_2 , 0x3F000000, 0x3FE0000000000000) // IEEE-754 floating-point [0.5, 1) exponent interval
00030     CONST(Expo1   , 0x3F800000, 0x3FF0000000000000) // IEEE-754 floating-point [ 1, 2) exponent interval
00031     CONST(Expo2   , 0x40000000, 0x4000000000000000) // IEEE-754 floating-point [ 2, 4) exponent interval
00032     CONST(Expo4   , 0x40800000, 0x4010000000000000) // IEEE-754 floating-point [ 4, 8) exponent interval
00033     CONST(ExpoNeg1, 0xBF800000, 0xBFF0000000000000) // IEEE-754 floating-point [-1,-2) exponent interval
00034 #undef CONST
00035 
00036 const float justUnder1f = 0.99999997f; //0x3f7fffff;
00037 
00038 
00040 #if defined(__ppc__)
00041     const int endian = 1;
00042 #else
00043     const int endian = 0;
00044 #endif
00045 
00046 inline bool isLittleEndian(){ return endian==0; }
00047 
00048 namespace{
00049     const double roundMagic = 6755399441055744.; // 2^52 * 1.5
00050     
00051     template<class T> const T roundEps();
00052     template<> inline const float  roundEps<float >(){ return 0.499999925f; }
00053     template<> inline const double roundEps<double>(){ return 0.499999985; }
00054 }
00055 
00056 
00057 // constant macros
00058 
00059 // const double pi = 4*atan(1.0);
00060 
00061 // math.h sometimes does not include these ANSI C macros.
00062 #ifndef M_E
00063 #define M_E         2.71828182845904523536028747135266250
00064 #endif
00065 #ifndef M_LOG2E
00066 #define M_LOG2E     1.44269504088896340735992468100189214
00067 #endif
00068 #ifndef M_LOG10E
00069 #define M_LOG10E    0.434294481903251827651128918916605082
00070 #endif
00071 #ifndef M_LN2
00072 #define M_LN2       0.693147180559945309417232121458176568
00073 #endif
00074 #ifndef M_LN10
00075 #define M_LN10      2.30258509299404568401799145468436421
00076 #endif
00077 #ifndef M_PI
00078 #define M_PI        3.14159265358979323846264338327950288
00079 #endif
00080 #ifndef M_PI_2
00081 #define M_PI_2      1.57079632679489661923132169163975144
00082 #endif
00083 #ifndef M_PI_4
00084 #define M_PI_4      0.785398163397448309615660845819875721
00085 #endif
00086 #ifndef M_1_PI
00087 #define M_1_PI      0.318309886183790671537767526745028724
00088 #endif
00089 #ifndef M_2_PI
00090 #define M_2_PI      0.636619772367581343075535053490057448
00091 #endif
00092 #ifndef M_2_SQRTPI
00093 #define M_2_SQRTPI  1.12837916709551257389615890312154517
00094 #endif
00095 #ifndef M_SQRT2
00096 #define M_SQRT2     1.41421356237309504880168872420969808
00097 #endif
00098 #ifndef M_SQRT1_2
00099 #define M_SQRT1_2   0.707106781186547524400844362104849039
00100 #endif
00101 
00102 // Some other useful constants
00103 #ifndef M_2PI
00104 #define M_2PI       6.283185307179586231941716828464095101      // 2pi
00105 #endif
00106 #ifndef M_4PI
00107 #define M_4PI       12.566370614359172463937643765552465425     // 4pi
00108 #endif
00109 #ifndef M_1_2PI
00110 #define M_1_2PI     0.159154943091895345554011992339482617      // 1/(2pi)
00111 #endif
00112 #ifndef M_3PI_2
00113 #define M_3PI_2     4.712388980384689673996945202816277742      // 3pi/2
00114 #endif
00115 #ifndef M_3PI_4
00116 #define M_3PI_4     2.356194490192343282632028017564707056      // 3pi/4
00117 #endif
00118 #ifndef M_LN001     
00119 #define M_LN001     -6.90775527898                              // ln(0.001)
00120 #endif
00121 
00122 // Function for getting values
00123 // printf("%.36Lf\n", 4.0 * M_PI);
00124 
00125 } // gam::
00126 
00127 #endif