00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_RECURSION_UTILITIES_INCLUDE
00013 #define MTL_RECURSION_UTILITIES_INCLUDE
00014
00015 #include <limits>
00016 #include <cmath>
00017
00018 namespace mtl { namespace recursion {
00019
00020
00021
00022 std::size_t inline first_part(std::size_t n)
00023 {
00024 if (n == 0) return 0;
00025
00026 std::size_t i= std::numeric_limits<std::size_t>::max()/2 + 1;
00027
00028 while(i >= n) i>>= 1;
00029 return i;
00030 }
00031
00032
00033
00034 std::size_t inline second_part(std::size_t n)
00035 {
00036 return n - first_part(n);
00037 }
00038
00039
00040 template <typename Matrix>
00041 std::size_t inline outer_bound(Matrix const& matrix)
00042 {
00043 std::size_t max_dim=std::max(num_rows(matrix), num_cols(matrix)), bound= 1;
00044 for (; bound < max_dim;) bound<<= 1;
00045 return bound;
00046 }
00047
00048
00049 template <typename Integral>
00050 Integral inline least_significant_one_bit(Integral x)
00051 {
00052 return ((x ^ (x-1)) + 1) >> 1;
00053 }
00054
00055
00056 template <typename Integral>
00057 bool inline is_power_of_2(Integral x)
00058 {
00059 return x == least_significant_one_bit(x);
00060 }
00061
00062
00063 }}
00064
00065 #endif // MTL_RECURSION_UTILITIES_INCLUDE