~
[scx.git] / include / Math.hpp
blob3fcdefa0bcb448dbe379667254a37ca62764feb7
1 #ifndef SCX_ROUNDOFF_HPP
2 #define SCX_ROUNDOFF_HPP
4 #include <cmath>
5 #include <sstream>
6 using namespace std;
8 namespace scx {
10 static inline double RoundOff(double num, int n)
12 int scale = pow((double)10, n);
13 num += 0.5 * pow((double)0.1, n);
14 num *= scale;
15 num = (int)num;
16 num /= scale;
17 return num;
20 template<class T>
21 static inline bool IsOdd(T n)
23 return (n & 1);
26 template<class T>
27 static inline bool IsEven(T n)
29 return !(n & 1);
32 // only for unsigned
33 template<class T>
34 static inline bool Is2Exp(T n)
36 return !(n & (n-1));
39 template<typename T>
40 static inline bool Not2Exp(T n)
42 return (n & (n-1));
47 #endif