utype_helper.hpp 6.0 KB

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