00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ROOT_Math_Math
00014 #define ROOT_Math_Math
00015
00016 #ifdef _WIN32
00017 #define _USE_MATH_DEFINES
00018 #define HAVE_NO_LOG1P
00019 #define HAVE_NO_EXPM1
00020 #endif
00021
00022 #include <cmath>
00023
00024 #if defined(__sun)
00025
00026 #include <math.h>
00027 #endif
00028
00029
00030 #ifdef HAVE_NO_EXPM1
00031
00032 #include <limits>
00033 #endif
00034
00035
00036 #ifndef M_PI
00037
00038 #define M_PI 3.14159265358979323846264338328 // Pi
00039 #endif
00040
00041 #ifndef M_PI_2
00042 #define M_PI_2 1.57079632679489661923132169164 // Pi/2
00043 #endif
00044
00045 #ifndef M_PI_4
00046 #define M_PI_4 0.78539816339744830961566084582 // Pi/4
00047 #endif
00048
00049 namespace ROOT {
00050
00051 namespace Math {
00052
00053
00054
00055
00056 inline double Pi() { return M_PI; }
00057
00058
00059
00060
00061
00062
00063 inline double log1p( double x) {
00064 #ifndef HAVE_NO_LOG1P
00065 return ::log1p(x);
00066 #else
00067
00068 volatile double y;
00069 y = 1 + x;
00070 return std::log(y) - ((y-1)-x)/y ;
00071 #endif
00072 }
00073
00074 inline double expm1( double x) {
00075 #ifndef HAVE_NO_EXPM1
00076 return ::expm1(x);
00077 #else
00078
00079
00080 if (std::abs(x) < 0.5)
00081 {
00082
00083
00084 double i = 1.0;
00085 double sum = x;
00086 double term = x / 1.0;
00087 do {
00088 i++ ;
00089 term *= x/i;
00090 sum += term;
00091 }
00092 while (std::abs(term) > std::abs(sum) * std::numeric_limits<double>::epsilon() ) ;
00093
00094 return sum ;
00095 }
00096 else
00097 {
00098 return std::exp(x) - 1;
00099 }
00100 #endif
00101 }
00102
00103
00104 }
00105
00106 }
00107
00108
00109 #endif