]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/multiprecision/include/boost/multiprecision/cpp_int/cpp_int_config.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / multiprecision / include / boost / multiprecision / cpp_int / cpp_int_config.hpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////
2// Copyright 2012 John Maddock. Distributed under the Boost
3// Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
5
6#ifndef BOOST_MP_CPP_INT_CORE_HPP
7#define BOOST_MP_CPP_INT_CORE_HPP
8
9#include <boost/integer.hpp>
10#include <boost/integer_traits.hpp>
11#include <boost/mpl/if.hpp>
12#include <boost/mpl/int.hpp>
13#include <boost/static_assert.hpp>
14#include <boost/assert.hpp>
15
16namespace boost{ namespace multiprecision{
17
18namespace detail{
19
20//
21// These traits calculate the largest type in the list
22// [unsigned] boost::long_long_type, long, int, which has the specified number
23// of bits. Note that intN_t and boost::int_t<N> find the first
24// member of the above list, not the last. We want the last in the
25// list to ensure that mixed arithmetic operations are as efficient
26// as possible.
27//
28template <unsigned N>
29struct largest_signed_type
30{
31 typedef typename mpl::if_c<
32 1 + std::numeric_limits<boost::long_long_type>::digits == N,
33 boost::long_long_type,
34 typename mpl::if_c<
35 1 + std::numeric_limits<long>::digits == N,
36 long,
37 typename mpl::if_c<
38 1 + std::numeric_limits<int>::digits == N,
39 int,
40 typename boost::int_t<N>::exact
41 >::type
42 >::type
43 >::type type;
44};
45
46template <unsigned N>
47struct largest_unsigned_type
48{
49 typedef typename mpl::if_c<
50 std::numeric_limits<boost::ulong_long_type>::digits == N,
51 boost::ulong_long_type,
52 typename mpl::if_c<
53 std::numeric_limits<unsigned long>::digits == N,
54 unsigned long,
55 typename mpl::if_c<
56 std::numeric_limits<unsigned int>::digits == N,
57 unsigned int,
58 typename boost::uint_t<N>::exact
59 >::type
60 >::type
61 >::type type;
62};
63
64} // namespace detail
65
66#if defined(BOOST_HAS_INT128)
67
68typedef detail::largest_unsigned_type<64>::type limb_type;
69typedef detail::largest_signed_type<64>::type signed_limb_type;
70typedef boost::uint128_type double_limb_type;
71typedef boost::int128_type signed_double_limb_type;
72static const limb_type max_block_10 = 1000000000000000000uLL;
73static const limb_type digits_per_block_10 = 18;
74
75inline limb_type block_multiplier(unsigned count)
76{
77 static const limb_type values[digits_per_block_10]
78 = { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000, 100000000000000000, 1000000000000000000 };
79 BOOST_ASSERT(count < digits_per_block_10);
80 return values[count];
81}
82
83// Can't do formatted IO on an __int128
84#define BOOST_MP_NO_DOUBLE_LIMB_TYPE_IO
85
86// Need to specialise integer_traits for __int128 as it's not a normal native type:
87} // namespace multiprecision
88
89template<>
90class integer_traits<multiprecision::double_limb_type>
91 : public std::numeric_limits<multiprecision::double_limb_type>,
92 public detail::integer_traits_base<multiprecision::double_limb_type, 0, ~static_cast<multiprecision::double_limb_type>(0)>
93{ };
94template<>
95class integer_traits<multiprecision::signed_double_limb_type>
96 : public std::numeric_limits<multiprecision::signed_double_limb_type>,
97 public detail::integer_traits_base<multiprecision::signed_double_limb_type, static_cast<multiprecision::signed_double_limb_type>((static_cast<multiprecision::double_limb_type>(1) << 127)), static_cast<multiprecision::signed_double_limb_type>(((~static_cast<multiprecision::double_limb_type>(0)) >> 1))>
98{ };
99
100namespace multiprecision{
101
102#else
103
104typedef detail::largest_unsigned_type<32>::type limb_type;
105typedef detail::largest_signed_type<32>::type signed_limb_type;
106typedef detail::largest_unsigned_type<64>::type double_limb_type;
107typedef detail::largest_signed_type<64>::type signed_double_limb_type;
108static const limb_type max_block_10 = 1000000000;
109static const limb_type digits_per_block_10 = 9;
110
111inline limb_type block_multiplier(unsigned count)
112{
113 static const limb_type values[digits_per_block_10]
114 = { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
115 BOOST_ASSERT(count < digits_per_block_10);
116 return values[count];
117}
118
119#endif
120
121static const unsigned bits_per_limb = sizeof(limb_type) * CHAR_BIT;
122
123template <class T>
124inline void minmax(const T& a, const T& b, T& aa, T& bb)
125{
126 if(a < b)
127 {
128 aa = a;
129 bb = b;
130 }
131 else
132 {
133 aa = b;
134 bb = a;
135 }
136}
137
138enum cpp_integer_type
139{
140 signed_magnitude = 1,
141 unsigned_magnitude = 0,
142 signed_packed = 3,
143 unsigned_packed = 2
144};
145
146enum cpp_int_check_type
147{
148 checked = 1,
149 unchecked = 0
150};
151
152}}
153
154//
155// Figure out whether to support user-defined-literals or not:
156//
157#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_USER_DEFINED_LITERALS) \
158 && !defined(BOOST_NO_CXX11_CONSTEXPR)
159# define BOOST_MP_USER_DEFINED_LITERALS
160#endif
161
162#endif // BOOST_MP_CPP_INT_CORE_HPP
163