/////////////////////////////////////////////////////////////// // Copyright 2012 - 2021 John Maddock. // Copyright 2021 Matt Borland. // Distributed under the Boost Software License, Version 1.0. // See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt #ifndef BOOST_MP_CPP_INT_CONFIG_HPP #define BOOST_MP_CPP_INT_CONFIG_HPP #include #include #include #include #include namespace boost { namespace multiprecision { namespace detail { // // These traits calculate the largest type in the list // [unsigned] long long, long, int, which has the specified number // of bits. Note that int_t and uint_t find the first // member of the above list, not the last. We want the last in the // list to ensure that mixed arithmetic operations are as efficient // as possible. // template struct int_t { using exact = typename std::conditional::type>::type>::type>::type>::type; using least = typename std::conditional::digits, signed char, typename std::conditional::digits, short, typename std::conditional::digits, int, typename std::conditional::digits, long, typename std::conditional::digits, long long, void >::type>::type>::type>::type>::type; static_assert(!std::is_same::value && !std::is_same::value, "Number of bits does not match any standard data type. \ Please file an issue at https://github.com/boostorg/multiprecision/ referencing this error from cpp_int_config.hpp"); }; template struct uint_t { using exact = typename std::conditional::type>::type>::type>::type>::type; using least = typename std::conditional::digits, unsigned char, typename std::conditional::digits, unsigned short, typename std::conditional::digits, unsigned int, typename std::conditional::digits, unsigned long, typename std::conditional::digits, unsigned long long, void >::type>::type>::type>::type>::type; static_assert(!std::is_same::value && !std::is_same::value, "Number of bits does not match any standard data type. \ Please file an issue at https://github.com/boostorg/multiprecision/ referencing this error from cpp_int_config.hpp"); }; template struct largest_signed_type { using type = typename std::conditional< 1 + std::numeric_limits::digits == N, long long, typename std::conditional< 1 + std::numeric_limits::digits == N, long, typename std::conditional< 1 + std::numeric_limits::digits == N, int, typename int_t::exact>::type>::type>::type; }; template struct largest_unsigned_type { using type = typename std::conditional< std::numeric_limits::digits == N, unsigned long long, typename std::conditional< std::numeric_limits::digits == N, unsigned long, typename std::conditional< std::numeric_limits::digits == N, unsigned int, typename uint_t::exact>::type>::type>::type; }; } // namespace detail #if defined(BOOST_HAS_INT128) using limb_type = detail::largest_unsigned_type<64>::type; using signed_limb_type = detail::largest_signed_type<64>::type; using double_limb_type = boost::multiprecision::uint128_type; using signed_double_limb_type = boost::multiprecision::int128_type; constexpr limb_type max_block_10 = 1000000000000000000uLL; constexpr limb_type digits_per_block_10 = 18; inline BOOST_MP_CXX14_CONSTEXPR limb_type block_multiplier(std::size_t count) { constexpr limb_type values[digits_per_block_10] = {10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000, 100000000000000000, 1000000000000000000}; BOOST_MP_ASSERT(count < digits_per_block_10); return values[count]; } // Can't do formatted IO on an __int128 #define BOOST_MP_NO_DOUBLE_LIMB_TYPE_IO #else using limb_type = detail::largest_unsigned_type<32>::type; using signed_limb_type = detail::largest_signed_type<32>::type ; using double_limb_type = detail::largest_unsigned_type<64>::type; using signed_double_limb_type = detail::largest_signed_type<64>::type ; constexpr limb_type max_block_10 = 1000000000; constexpr limb_type digits_per_block_10 = 9; inline limb_type block_multiplier(std::size_t count) { constexpr limb_type values[digits_per_block_10] = {10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; BOOST_MP_ASSERT(count < digits_per_block_10); return values[count]; } #endif constexpr std::size_t bits_per_limb = sizeof(limb_type) * CHAR_BIT; template inline BOOST_MP_CXX14_CONSTEXPR void minmax(const T& a, const T& b, T& aa, T& bb) { if (a < b) { aa = a; bb = b; } else { aa = b; bb = a; } } } // namespace multiprecision } // namespace boost #endif // BOOST_MP_CPP_INT_CONFIG_HPP