1 /////////////////////////////////////////////////////////////////////////////// 2 // Copyright 2012 John Maddock. 3 // Copyright Christopher Kormanyos 2013. Distributed under the Boost 4 // Software License, Version 1.0. (See accompanying file 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 8 #ifndef BOOST_MP_UTYPE_HELPER_HPP 9 #define BOOST_MP_UTYPE_HELPER_HPP 10 11 #include <limits> 12 #include <boost/cstdint.hpp> 13 14 namespace boost { namespace multiprecision { 15 namespace detail 16 { 17 template<const unsigned> struct utype_helper { typedef boost::uint64_t exact; }; 18 template<> struct utype_helper<0U> { typedef boost::uint8_t exact; }; 19 template<> struct utype_helper<1U> { typedef boost::uint8_t exact; }; 20 template<> struct utype_helper<2U> { typedef boost::uint8_t exact; }; 21 template<> struct utype_helper<3U> { typedef boost::uint8_t exact; }; 22 template<> struct utype_helper<4U> { typedef boost::uint8_t exact; }; 23 template<> struct utype_helper<5U> { typedef boost::uint8_t exact; }; 24 template<> struct utype_helper<6U> { typedef boost::uint8_t exact; }; 25 template<> struct utype_helper<7U> { typedef boost::uint8_t exact; }; 26 template<> struct utype_helper<8U> { typedef boost::uint8_t exact; }; 27 28 template<> struct utype_helper<9U> { typedef boost::uint16_t exact; }; 29 template<> struct utype_helper<10U> { typedef boost::uint16_t exact; }; 30 template<> struct utype_helper<11U> { typedef boost::uint16_t exact; }; 31 template<> struct utype_helper<12U> { typedef boost::uint16_t exact; }; 32 template<> struct utype_helper<13U> { typedef boost::uint16_t exact; }; 33 template<> struct utype_helper<14U> { typedef boost::uint16_t exact; }; 34 template<> struct utype_helper<15U> { typedef boost::uint16_t exact; }; 35 template<> struct utype_helper<16U> { typedef boost::uint16_t exact; }; 36 37 template<> struct utype_helper<17U> { typedef boost::uint32_t exact; }; 38 template<> struct utype_helper<18U> { typedef boost::uint32_t exact; }; 39 template<> struct utype_helper<19U> { typedef boost::uint32_t exact; }; 40 template<> struct utype_helper<20U> { typedef boost::uint32_t exact; }; 41 template<> struct utype_helper<21U> { typedef boost::uint32_t exact; }; 42 template<> struct utype_helper<22U> { typedef boost::uint32_t exact; }; 43 template<> struct utype_helper<23U> { typedef boost::uint32_t exact; }; 44 template<> struct utype_helper<24U> { typedef boost::uint32_t exact; }; 45 template<> struct utype_helper<25U> { typedef boost::uint32_t exact; }; 46 template<> struct utype_helper<26U> { typedef boost::uint32_t exact; }; 47 template<> struct utype_helper<27U> { typedef boost::uint32_t exact; }; 48 template<> struct utype_helper<28U> { typedef boost::uint32_t exact; }; 49 template<> struct utype_helper<29U> { typedef boost::uint32_t exact; }; 50 template<> struct utype_helper<30U> { typedef boost::uint32_t exact; }; 51 template<> struct utype_helper<31U> { typedef boost::uint32_t exact; }; 52 template<> struct utype_helper<32U> { typedef boost::uint32_t exact; }; 53 54 template<> struct utype_helper<33U> { typedef boost::uint64_t exact; }; 55 template<> struct utype_helper<34U> { typedef boost::uint64_t exact; }; 56 template<> struct utype_helper<35U> { typedef boost::uint64_t exact; }; 57 template<> struct utype_helper<36U> { typedef boost::uint64_t exact; }; 58 template<> struct utype_helper<37U> { typedef boost::uint64_t exact; }; 59 template<> struct utype_helper<38U> { typedef boost::uint64_t exact; }; 60 template<> struct utype_helper<39U> { typedef boost::uint64_t exact; }; 61 template<> struct utype_helper<40U> { typedef boost::uint64_t exact; }; 62 template<> struct utype_helper<41U> { typedef boost::uint64_t exact; }; 63 template<> struct utype_helper<42U> { typedef boost::uint64_t exact; }; 64 template<> struct utype_helper<43U> { typedef boost::uint64_t exact; }; 65 template<> struct utype_helper<44U> { typedef boost::uint64_t exact; }; 66 template<> struct utype_helper<45U> { typedef boost::uint64_t exact; }; 67 template<> struct utype_helper<46U> { typedef boost::uint64_t exact; }; 68 template<> struct utype_helper<47U> { typedef boost::uint64_t exact; }; 69 template<> struct utype_helper<48U> { typedef boost::uint64_t exact; }; 70 template<> struct utype_helper<49U> { typedef boost::uint64_t exact; }; 71 template<> struct utype_helper<50U> { typedef boost::uint64_t exact; }; 72 template<> struct utype_helper<51U> { typedef boost::uint64_t exact; }; 73 template<> struct utype_helper<52U> { typedef boost::uint64_t exact; }; 74 template<> struct utype_helper<53U> { typedef boost::uint64_t exact; }; 75 template<> struct utype_helper<54U> { typedef boost::uint64_t exact; }; 76 template<> struct utype_helper<55U> { typedef boost::uint64_t exact; }; 77 template<> struct utype_helper<56U> { typedef boost::uint64_t exact; }; 78 template<> struct utype_helper<57U> { typedef boost::uint64_t exact; }; 79 template<> struct utype_helper<58U> { typedef boost::uint64_t exact; }; 80 template<> struct utype_helper<59U> { typedef boost::uint64_t exact; }; 81 template<> struct utype_helper<60U> { typedef boost::uint64_t exact; }; 82 template<> struct utype_helper<61U> { typedef boost::uint64_t exact; }; 83 template<> struct utype_helper<62U> { typedef boost::uint64_t exact; }; 84 template<> struct utype_helper<63U> { typedef boost::uint64_t exact; }; 85 template<> struct utype_helper<64U> { typedef boost::uint64_t exact; }; 86 87 template<class unsigned_type> utype_prior(unsigned_type ui)88 int utype_prior(unsigned_type ui) 89 { 90 // TBD: Implement a templated binary search for this. 91 int priority_bit; 92 93 unsigned_type priority_mask = unsigned_type(unsigned_type(1U) << (std::numeric_limits<unsigned_type>::digits - 1)); 94 95 for(priority_bit = std::numeric_limits<unsigned_type>::digits - 1; priority_bit >= 0; --priority_bit) 96 { 97 if(unsigned_type(priority_mask & ui) != unsigned_type(0U)) 98 { 99 break; 100 } 101 102 priority_mask >>= 1; 103 } 104 105 return priority_bit; 106 } 107 108 } } } 109 110 #endif // BOOST_MP_UTYPE_HELPER_HPP 111