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 { 15 namespace multiprecision { 16 namespace detail { 17 template <const unsigned> 18 struct utype_helper 19 { 20 typedef boost::uint64_t exact; 21 }; 22 template <> 23 struct utype_helper<0U> 24 { 25 typedef boost::uint8_t exact; 26 }; 27 template <> 28 struct utype_helper<1U> 29 { 30 typedef boost::uint8_t exact; 31 }; 32 template <> 33 struct utype_helper<2U> 34 { 35 typedef boost::uint8_t exact; 36 }; 37 template <> 38 struct utype_helper<3U> 39 { 40 typedef boost::uint8_t exact; 41 }; 42 template <> 43 struct utype_helper<4U> 44 { 45 typedef boost::uint8_t exact; 46 }; 47 template <> 48 struct utype_helper<5U> 49 { 50 typedef boost::uint8_t exact; 51 }; 52 template <> 53 struct utype_helper<6U> 54 { 55 typedef boost::uint8_t exact; 56 }; 57 template <> 58 struct utype_helper<7U> 59 { 60 typedef boost::uint8_t exact; 61 }; 62 template <> 63 struct utype_helper<8U> 64 { 65 typedef boost::uint8_t exact; 66 }; 67 68 template <> 69 struct utype_helper<9U> 70 { 71 typedef boost::uint16_t exact; 72 }; 73 template <> 74 struct utype_helper<10U> 75 { 76 typedef boost::uint16_t exact; 77 }; 78 template <> 79 struct utype_helper<11U> 80 { 81 typedef boost::uint16_t exact; 82 }; 83 template <> 84 struct utype_helper<12U> 85 { 86 typedef boost::uint16_t exact; 87 }; 88 template <> 89 struct utype_helper<13U> 90 { 91 typedef boost::uint16_t exact; 92 }; 93 template <> 94 struct utype_helper<14U> 95 { 96 typedef boost::uint16_t exact; 97 }; 98 template <> 99 struct utype_helper<15U> 100 { 101 typedef boost::uint16_t exact; 102 }; 103 template <> 104 struct utype_helper<16U> 105 { 106 typedef boost::uint16_t exact; 107 }; 108 109 template <> 110 struct utype_helper<17U> 111 { 112 typedef boost::uint32_t exact; 113 }; 114 template <> 115 struct utype_helper<18U> 116 { 117 typedef boost::uint32_t exact; 118 }; 119 template <> 120 struct utype_helper<19U> 121 { 122 typedef boost::uint32_t exact; 123 }; 124 template <> 125 struct utype_helper<20U> 126 { 127 typedef boost::uint32_t exact; 128 }; 129 template <> 130 struct utype_helper<21U> 131 { 132 typedef boost::uint32_t exact; 133 }; 134 template <> 135 struct utype_helper<22U> 136 { 137 typedef boost::uint32_t exact; 138 }; 139 template <> 140 struct utype_helper<23U> 141 { 142 typedef boost::uint32_t exact; 143 }; 144 template <> 145 struct utype_helper<24U> 146 { 147 typedef boost::uint32_t exact; 148 }; 149 template <> 150 struct utype_helper<25U> 151 { 152 typedef boost::uint32_t exact; 153 }; 154 template <> 155 struct utype_helper<26U> 156 { 157 typedef boost::uint32_t exact; 158 }; 159 template <> 160 struct utype_helper<27U> 161 { 162 typedef boost::uint32_t exact; 163 }; 164 template <> 165 struct utype_helper<28U> 166 { 167 typedef boost::uint32_t exact; 168 }; 169 template <> 170 struct utype_helper<29U> 171 { 172 typedef boost::uint32_t exact; 173 }; 174 template <> 175 struct utype_helper<30U> 176 { 177 typedef boost::uint32_t exact; 178 }; 179 template <> 180 struct utype_helper<31U> 181 { 182 typedef boost::uint32_t exact; 183 }; 184 template <> 185 struct utype_helper<32U> 186 { 187 typedef boost::uint32_t exact; 188 }; 189 190 template <> 191 struct utype_helper<33U> 192 { 193 typedef boost::uint64_t exact; 194 }; 195 template <> 196 struct utype_helper<34U> 197 { 198 typedef boost::uint64_t exact; 199 }; 200 template <> 201 struct utype_helper<35U> 202 { 203 typedef boost::uint64_t exact; 204 }; 205 template <> 206 struct utype_helper<36U> 207 { 208 typedef boost::uint64_t exact; 209 }; 210 template <> 211 struct utype_helper<37U> 212 { 213 typedef boost::uint64_t exact; 214 }; 215 template <> 216 struct utype_helper<38U> 217 { 218 typedef boost::uint64_t exact; 219 }; 220 template <> 221 struct utype_helper<39U> 222 { 223 typedef boost::uint64_t exact; 224 }; 225 template <> 226 struct utype_helper<40U> 227 { 228 typedef boost::uint64_t exact; 229 }; 230 template <> 231 struct utype_helper<41U> 232 { 233 typedef boost::uint64_t exact; 234 }; 235 template <> 236 struct utype_helper<42U> 237 { 238 typedef boost::uint64_t exact; 239 }; 240 template <> 241 struct utype_helper<43U> 242 { 243 typedef boost::uint64_t exact; 244 }; 245 template <> 246 struct utype_helper<44U> 247 { 248 typedef boost::uint64_t exact; 249 }; 250 template <> 251 struct utype_helper<45U> 252 { 253 typedef boost::uint64_t exact; 254 }; 255 template <> 256 struct utype_helper<46U> 257 { 258 typedef boost::uint64_t exact; 259 }; 260 template <> 261 struct utype_helper<47U> 262 { 263 typedef boost::uint64_t exact; 264 }; 265 template <> 266 struct utype_helper<48U> 267 { 268 typedef boost::uint64_t exact; 269 }; 270 template <> 271 struct utype_helper<49U> 272 { 273 typedef boost::uint64_t exact; 274 }; 275 template <> 276 struct utype_helper<50U> 277 { 278 typedef boost::uint64_t exact; 279 }; 280 template <> 281 struct utype_helper<51U> 282 { 283 typedef boost::uint64_t exact; 284 }; 285 template <> 286 struct utype_helper<52U> 287 { 288 typedef boost::uint64_t exact; 289 }; 290 template <> 291 struct utype_helper<53U> 292 { 293 typedef boost::uint64_t exact; 294 }; 295 template <> 296 struct utype_helper<54U> 297 { 298 typedef boost::uint64_t exact; 299 }; 300 template <> 301 struct utype_helper<55U> 302 { 303 typedef boost::uint64_t exact; 304 }; 305 template <> 306 struct utype_helper<56U> 307 { 308 typedef boost::uint64_t exact; 309 }; 310 template <> 311 struct utype_helper<57U> 312 { 313 typedef boost::uint64_t exact; 314 }; 315 template <> 316 struct utype_helper<58U> 317 { 318 typedef boost::uint64_t exact; 319 }; 320 template <> 321 struct utype_helper<59U> 322 { 323 typedef boost::uint64_t exact; 324 }; 325 template <> 326 struct utype_helper<60U> 327 { 328 typedef boost::uint64_t exact; 329 }; 330 template <> 331 struct utype_helper<61U> 332 { 333 typedef boost::uint64_t exact; 334 }; 335 template <> 336 struct utype_helper<62U> 337 { 338 typedef boost::uint64_t exact; 339 }; 340 template <> 341 struct utype_helper<63U> 342 { 343 typedef boost::uint64_t exact; 344 }; 345 template <> 346 struct utype_helper<64U> 347 { 348 typedef boost::uint64_t exact; 349 }; 350 351 template <class unsigned_type> utype_prior(unsigned_type ui)352int utype_prior(unsigned_type ui) 353 { 354 // TBD: Implement a templated binary search for this. 355 int priority_bit; 356 357 unsigned_type priority_mask = unsigned_type(unsigned_type(1U) << (std::numeric_limits<unsigned_type>::digits - 1)); 358 359 for (priority_bit = std::numeric_limits<unsigned_type>::digits - 1; priority_bit >= 0; --priority_bit) 360 { 361 if (unsigned_type(priority_mask & ui) != unsigned_type(0U)) 362 { 363 break; 364 } 365 366 priority_mask >>= 1; 367 } 368 369 return priority_bit; 370 } 371 372 }}} // namespace boost::multiprecision::detail 373 374 #endif // BOOST_MP_UTYPE_HELPER_HPP 375