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 #ifndef METALIC_MATH_HH
00029 # define METALIC_MATH_HH
00030
00031 # include <mlc/bool.hh>
00032
00033 namespace mlc
00034 {
00035
00036 namespace internal
00037 {
00038
00039
00040
00041 template<unsigned N> struct is_pow2 { typedef false_type ret; };
00042 template<> struct is_pow2<8> { typedef true_type ret; };
00043 template<> struct is_pow2<16> { typedef true_type ret; };
00044 template<> struct is_pow2<32> { typedef true_type ret; };
00045 template<> struct is_pow2<64> { typedef true_type ret; };
00046
00047 template<unsigned N, class> struct find_pow2sup;
00048 template<unsigned N> struct find_pow2sup<N,true_type> {
00049 enum { value = N };
00050 };
00051 template<unsigned N> struct find_pow2sup<N,false_type> {
00052 enum { value = find_pow2sup< N+1,
00053 typename is_pow2<N+1>::ret >::value };
00054 };
00055
00056 }
00057
00058
00059
00060 template<unsigned N>
00061 struct pow2sup {
00062 enum {
00063 value =
00064 internal::find_pow2sup< N,
00065 typename internal::is_pow2<N>::ret >::value
00066 };
00067 private:
00068 typedef typename is_true<N < 32>::ensure_type precondition_type;
00069 };
00070
00071
00072
00073 template<unsigned N>
00074 class utest {
00075 public:
00076 typedef typename is_true<N/2 == (N+1)/2>::ensure_type is_odd_type;
00077 static void ensure_odd() { is_odd_type::is_true(); }
00078 };
00079
00080 }
00081
00082 #endif // METALIC_MATH_HH