00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <cmath>
00029 #include <OpenMS/CONCEPT/Types.h>
00030
00031
00032 #ifndef OPENMS_MATH_MISC_MATHFUNCTIONS_H
00033 #define OPENMS_MATH_MISC_MATHFUNCTIONS_H
00034
00035
00036 #ifndef isnan
00037 # define isnan(x) \
00038 (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
00039 : sizeof (x) == sizeof (double) ? isnan_d (x) \
00040 : isnan_f (x))
00041 static inline int isnan_f (float x) { return x != x; }
00042 static inline int isnan_d (double x) { return x != x; }
00043 static inline int isnan_ld (long double x) { return x != x; }
00044 #endif
00045
00046 #ifndef isinf
00047 # define isinf(x) \
00048 (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
00049 : sizeof (x) == sizeof (double) ? isinf_d (x) \
00050 : isinf_f (x))
00051 static inline int isinf_f (float x) { return isnan (x - x); }
00052 static inline int isinf_d (double x) { return isnan (x - x); }
00053 static inline int isinf_ld (long double x) { return isnan (x - x); }
00054 #endif
00055
00056 namespace OpenMS
00057 {
00065 namespace Math
00066 {
00078 inline static double ceil_decimal(double x, int decPow)
00079 {
00080 return (ceil(x/pow(10,decPow)))*pow(10,decPow);
00081 }
00082
00093 inline static double round_decimal(double x, int decPow)
00094 {
00095 if (x>0) return (floor(0.5+x/pow(10,decPow)))*pow(10,decPow);
00096 return -((floor(0.5+fabs(x)/pow(10,decPow)))*pow(10,decPow));
00097 }
00098
00104 inline static double intervalTransformation(double x,double left1,double right1,double left2,double right2)
00105 {
00106 return left2 + (x - left1) * (right2 - left2) / (right1 - left1);
00107 }
00108
00116 inline double linear2log(double x)
00117 {
00118 return log10(x+1);
00119 }
00120
00128 inline double log2linear(double x)
00129 {
00130 return pow(10,x)-1;
00131 }
00132
00138 inline bool isOdd(UInt x)
00139 {
00140 return ((x & 1)!=0);
00141 }
00142
00143 }
00144 }
00145
00146 #endif // OPENMS_MATH_MISC_MATHFUNCTIONS_H