annotate DEPENDENCIES/generic/include/boost/multiprecision/cpp_int/literals.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 ///////////////////////////////////////////////////////////////
Chris@16 2 // Copyright 2013 John Maddock. Distributed under the Boost
Chris@16 3 // Software License, Version 1.0. (See accompanying file
Chris@16 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
Chris@16 5
Chris@16 6 #ifndef BOOST_MP_CPP_INT_LITERALS_HPP
Chris@16 7 #define BOOST_MP_CPP_INT_LITERALS_HPP
Chris@16 8
Chris@16 9 #include <boost/multiprecision/cpp_int/cpp_int_config.hpp>
Chris@16 10
Chris@16 11 namespace boost{ namespace multiprecision{
Chris@16 12
Chris@16 13 namespace literals{ namespace detail{
Chris@16 14
Chris@16 15 template <char> struct hex_value;
Chris@16 16 template <> struct hex_value<'0'> { static constexpr limb_type value = 0; };
Chris@16 17 template <> struct hex_value<'1'> { static constexpr limb_type value = 1; };
Chris@16 18 template <> struct hex_value<'2'> { static constexpr limb_type value = 2; };
Chris@16 19 template <> struct hex_value<'3'> { static constexpr limb_type value = 3; };
Chris@16 20 template <> struct hex_value<'4'> { static constexpr limb_type value = 4; };
Chris@16 21 template <> struct hex_value<'5'> { static constexpr limb_type value = 5; };
Chris@16 22 template <> struct hex_value<'6'> { static constexpr limb_type value = 6; };
Chris@16 23 template <> struct hex_value<'7'> { static constexpr limb_type value = 7; };
Chris@16 24 template <> struct hex_value<'8'> { static constexpr limb_type value = 8; };
Chris@16 25 template <> struct hex_value<'9'> { static constexpr limb_type value = 9; };
Chris@16 26 template <> struct hex_value<'a'> { static constexpr limb_type value = 10; };
Chris@16 27 template <> struct hex_value<'b'> { static constexpr limb_type value = 11; };
Chris@16 28 template <> struct hex_value<'c'> { static constexpr limb_type value = 12; };
Chris@16 29 template <> struct hex_value<'d'> { static constexpr limb_type value = 13; };
Chris@16 30 template <> struct hex_value<'e'> { static constexpr limb_type value = 14; };
Chris@16 31 template <> struct hex_value<'f'> { static constexpr limb_type value = 15; };
Chris@16 32 template <> struct hex_value<'A'> { static constexpr limb_type value = 10; };
Chris@16 33 template <> struct hex_value<'B'> { static constexpr limb_type value = 11; };
Chris@16 34 template <> struct hex_value<'C'> { static constexpr limb_type value = 12; };
Chris@16 35 template <> struct hex_value<'D'> { static constexpr limb_type value = 13; };
Chris@16 36 template <> struct hex_value<'E'> { static constexpr limb_type value = 14; };
Chris@16 37 template <> struct hex_value<'F'> { static constexpr limb_type value = 15; };
Chris@16 38
Chris@16 39 template <class Pack, limb_type value>
Chris@16 40 struct combine_value_to_pack;
Chris@16 41 template <limb_type first, limb_type...ARGS, limb_type value>
Chris@16 42 struct combine_value_to_pack<value_pack<first, ARGS...>, value>
Chris@16 43 {
Chris@16 44 typedef value_pack<first | value, ARGS...> type;
Chris@16 45 };
Chris@16 46
Chris@16 47 template <char NextChar, char...CHARS>
Chris@16 48 struct pack_values
Chris@16 49 {
Chris@16 50 static constexpr unsigned chars_per_limb = sizeof(limb_type) * CHAR_BIT / 4;
Chris@16 51 static constexpr unsigned shift = ((sizeof...(CHARS)) % chars_per_limb) * 4;
Chris@16 52 static constexpr limb_type value_to_add = shift ? hex_value<NextChar>::value << shift : hex_value<NextChar>::value;
Chris@16 53
Chris@16 54 typedef typename pack_values<CHARS...>::type recursive_packed_type;
Chris@16 55 typedef typename boost::mpl::if_c<shift == 0,
Chris@16 56 typename recursive_packed_type::next_type,
Chris@16 57 recursive_packed_type>::type pack_type;
Chris@16 58 typedef typename combine_value_to_pack<pack_type, value_to_add>::type type;
Chris@16 59 };
Chris@16 60 template <char NextChar>
Chris@16 61 struct pack_values<NextChar>
Chris@16 62 {
Chris@16 63 static constexpr limb_type value_to_add = hex_value<NextChar>::value;
Chris@16 64
Chris@16 65 typedef value_pack<value_to_add> type;
Chris@16 66 };
Chris@16 67
Chris@16 68 template <class T>
Chris@16 69 struct strip_leading_zeros_from_pack;
Chris@16 70 template <limb_type...PACK>
Chris@16 71 struct strip_leading_zeros_from_pack<value_pack<PACK...> >
Chris@16 72 {
Chris@16 73 typedef value_pack<PACK...> type;
Chris@16 74 };
Chris@16 75 template <limb_type...PACK>
Chris@16 76 struct strip_leading_zeros_from_pack<value_pack<0u, PACK...> >
Chris@16 77 {
Chris@16 78 typedef typename strip_leading_zeros_from_pack<value_pack<PACK...> >::type type;
Chris@16 79 };
Chris@16 80
Chris@16 81 template <limb_type v, class PACK>
Chris@16 82 struct append_value_to_pack;
Chris@16 83 template <limb_type v, limb_type...PACK>
Chris@16 84 struct append_value_to_pack<v, value_pack<PACK...> >
Chris@16 85 {
Chris@16 86 typedef value_pack<PACK..., v> type;
Chris@16 87 };
Chris@16 88
Chris@16 89 template <class T>
Chris@16 90 struct reverse_value_pack;
Chris@16 91 template <limb_type v, limb_type...VALUES>
Chris@16 92 struct reverse_value_pack<value_pack<v, VALUES...> >
Chris@16 93 {
Chris@16 94 typedef typename reverse_value_pack<value_pack<VALUES...> >::type lead_values;
Chris@16 95 typedef typename append_value_to_pack<v, lead_values>::type type;
Chris@16 96 };
Chris@16 97 template <limb_type v>
Chris@16 98 struct reverse_value_pack<value_pack<v> >
Chris@16 99 {
Chris@16 100 typedef value_pack<v> type;
Chris@16 101 };
Chris@16 102 template <>
Chris@16 103 struct reverse_value_pack<value_pack<> >
Chris@16 104 {
Chris@16 105 typedef value_pack<> type;
Chris@16 106 };
Chris@16 107
Chris@16 108 template <char l1, char l2, char...STR>
Chris@16 109 struct make_packed_value_from_str
Chris@16 110 {
Chris@16 111 BOOST_STATIC_ASSERT_MSG(l1 == '0', "Multi-precision integer literals must be in hexadecimal notation.");
Chris@16 112 BOOST_STATIC_ASSERT_MSG((l2 == 'X') || (l2 == 'x'), "Multi-precision integer literals must be in hexadecimal notation.");
Chris@16 113 typedef typename pack_values<STR...>::type packed_type;
Chris@16 114 typedef typename strip_leading_zeros_from_pack<packed_type>::type stripped_type;
Chris@16 115 typedef typename reverse_value_pack<stripped_type>::type type;
Chris@16 116 };
Chris@16 117
Chris@16 118 template <class Pack, class B>
Chris@16 119 struct make_backend_from_pack
Chris@16 120 {
Chris@16 121 static constexpr Pack p = {};
Chris@16 122 static constexpr B value = p;
Chris@16 123 };
Chris@16 124
Chris@16 125 template <class Pack, class B>
Chris@16 126 constexpr B make_backend_from_pack<Pack, B>::value;
Chris@16 127
Chris@16 128 template <unsigned Digits>
Chris@16 129 struct signed_cpp_int_literal_result_type
Chris@16 130 {
Chris@16 131 static constexpr unsigned bits = Digits * 4;
Chris@16 132 typedef boost::multiprecision::backends::cpp_int_backend<bits, bits, signed_magnitude, unchecked, void> backend_type;
Chris@16 133 typedef number<backend_type, et_off> number_type;
Chris@16 134 };
Chris@16 135
Chris@16 136 template <unsigned Digits>
Chris@16 137 struct unsigned_cpp_int_literal_result_type
Chris@16 138 {
Chris@16 139 static constexpr unsigned bits = Digits * 4;
Chris@16 140 typedef boost::multiprecision::backends::cpp_int_backend<bits, bits, unsigned_magnitude, unchecked, void> backend_type;
Chris@16 141 typedef number<backend_type, et_off> number_type;
Chris@16 142 };
Chris@16 143
Chris@16 144 }
Chris@16 145
Chris@16 146 template <char... STR>
Chris@16 147 constexpr typename boost::multiprecision::literals::detail::signed_cpp_int_literal_result_type<(sizeof...(STR)) - 2>::number_type operator "" _cppi()
Chris@16 148 {
Chris@16 149 typedef typename boost::multiprecision::literals::detail::make_packed_value_from_str<STR...>::type pt;
Chris@16 150 return boost::multiprecision::literals::detail::make_backend_from_pack<pt, typename boost::multiprecision::literals::detail::signed_cpp_int_literal_result_type<(sizeof...(STR)) - 2>::backend_type>::value;
Chris@16 151 }
Chris@16 152
Chris@16 153 template <char... STR>
Chris@16 154 constexpr typename boost::multiprecision::literals::detail::unsigned_cpp_int_literal_result_type<(sizeof...(STR)) - 2>::number_type operator "" _cppui()
Chris@16 155 {
Chris@16 156 typedef typename boost::multiprecision::literals::detail::make_packed_value_from_str<STR...>::type pt;
Chris@16 157 return boost::multiprecision::literals::detail::make_backend_from_pack<pt, typename boost::multiprecision::literals::detail::unsigned_cpp_int_literal_result_type<(sizeof...(STR)) - 2>::backend_type>::value;
Chris@16 158 }
Chris@16 159
Chris@16 160 #define BOOST_MP_DEFINE_SIZED_CPP_INT_LITERAL(Bits)\
Chris@16 161 template <char... STR> \
Chris@16 162 constexpr boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<Bits, Bits, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void> > operator "" BOOST_JOIN(_cppi, Bits)()\
Chris@16 163 {\
Chris@16 164 typedef typename boost::multiprecision::literals::detail::make_packed_value_from_str<STR...>::type pt;\
Chris@16 165 return boost::multiprecision::literals::detail::make_backend_from_pack<\
Chris@16 166 pt, \
Chris@16 167 boost::multiprecision::backends::cpp_int_backend<Bits, Bits, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void> \
Chris@16 168 >::value;\
Chris@16 169 }\
Chris@16 170 template <char... STR> \
Chris@16 171 constexpr boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<Bits, Bits, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void> > operator "" BOOST_JOIN(_cppui, Bits)()\
Chris@16 172 {\
Chris@16 173 typedef typename boost::multiprecision::literals::detail::make_packed_value_from_str<STR...>::type pt;\
Chris@16 174 return boost::multiprecision::literals::detail::make_backend_from_pack<\
Chris@16 175 pt, \
Chris@16 176 boost::multiprecision::backends::cpp_int_backend<Bits, Bits, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>\
Chris@16 177 >::value;\
Chris@16 178 }\
Chris@16 179
Chris@16 180 BOOST_MP_DEFINE_SIZED_CPP_INT_LITERAL(128)
Chris@16 181 BOOST_MP_DEFINE_SIZED_CPP_INT_LITERAL(256)
Chris@16 182 BOOST_MP_DEFINE_SIZED_CPP_INT_LITERAL(512)
Chris@16 183 BOOST_MP_DEFINE_SIZED_CPP_INT_LITERAL(1024)
Chris@16 184
Chris@16 185 }
Chris@16 186
Chris@16 187 //
Chris@16 188 // Overload unary minus operator for constexpr use:
Chris@16 189 //
Chris@16 190 template <unsigned MinBits, cpp_int_check_type Checked>
Chris@16 191 constexpr number<cpp_int_backend<MinBits, MinBits, signed_magnitude, Checked, void>, et_off>
Chris@16 192 operator - (const number<cpp_int_backend<MinBits, MinBits, signed_magnitude, Checked, void>, et_off>& a)
Chris@16 193 {
Chris@16 194 return cpp_int_backend<MinBits, MinBits, signed_magnitude, Checked, void>(a.backend(), boost::multiprecision::literals::detail::make_negate_tag());
Chris@16 195 }
Chris@16 196 template <unsigned MinBits, cpp_int_check_type Checked>
Chris@16 197 constexpr number<cpp_int_backend<MinBits, MinBits, signed_magnitude, Checked, void>, et_off>
Chris@16 198 operator - (number<cpp_int_backend<MinBits, MinBits, signed_magnitude, Checked, void>, et_off>&& a)
Chris@16 199 {
Chris@16 200 return cpp_int_backend<MinBits, MinBits, signed_magnitude, Checked, void>(static_cast<const number<cpp_int_backend<MinBits, MinBits, signed_magnitude, Checked, void>, et_off>&>(a).backend(), boost::multiprecision::literals::detail::make_negate_tag());
Chris@16 201 }
Chris@16 202
Chris@16 203 }} // namespaces
Chris@16 204
Chris@16 205 #endif // BOOST_MP_CPP_INT_CORE_HPP
Chris@16 206