/////////////////////////////////////////////////////////////////////////////// // Copyright 2011 John Maddock. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_MATH_BIG_NUM_BASE_HPP #define BOOST_MATH_BIG_NUM_BASE_HPP #include #include #include #include #include #include #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable : 4307) #endif #include #ifdef BOOST_MSVC #pragma warning(pop) #endif // // We now require C++11, if something we use is not supported, then error and say why: // #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_RVALUE_REFERENCES being set" #endif #ifdef BOOST_NO_CXX11_TEMPLATE_ALIASES #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_TEMPLATE_ALIASES being set" #endif #ifdef BOOST_NO_CXX11_HDR_ARRAY #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_HDR_ARRAY being set" #endif #ifdef BOOST_NO_CXX11_HDR_TYPE_TRAITS #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_HDR_TYPE_TRAITS being set" #endif #ifdef BOOST_NO_CXX11_ALLOCATOR #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_ALLOCATOR being set" #endif #ifdef BOOST_NO_CXX11_CONSTEXPR #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_CONSTEXPR being set" #endif #ifdef BOOST_MP_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_MP_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS being set" #endif #ifdef BOOST_NO_CXX11_REF_QUALIFIERS #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_REF_QUALIFIERS being set" #endif #ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_HDR_FUNCTIONAL being set" #endif #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_VARIADIC_TEMPLATES being set" #endif #ifdef BOOST_NO_CXX11_USER_DEFINED_LITERALS #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_USER_DEFINED_LITERALS being set" #endif #ifdef BOOST_NO_CXX11_DECLTYPE #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_DECLTYPE being set" #endif #ifdef BOOST_NO_CXX11_STATIC_ASSERT #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_STATIC_ASSERT being set" #endif #ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_DEFAULTED_FUNCTIONS being set" #endif #ifdef BOOST_NO_CXX11_NOEXCEPT #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_NOEXCEPT being set" #endif #ifdef BOOST_NO_CXX11_REF_QUALIFIERS #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_REF_QUALIFIERS being set" #endif #ifdef BOOST_NO_CXX11_USER_DEFINED_LITERALS #error "This library now requires a C++11 or later compiler - this message was generated as a result of BOOST_NO_CXX11_USER_DEFINED_LITERALS being set" #endif #if defined(NDEBUG) && !defined(_DEBUG) #define BOOST_MP_FORCEINLINE BOOST_FORCEINLINE #else #define BOOST_MP_FORCEINLINE inline #endif // // Thread local storage: // Note fails on Mingw, see https://sourceforge.net/p/mingw-w64/bugs/527/ // #if !defined(BOOST_NO_CXX11_THREAD_LOCAL) && !(defined(__MINGW32__) && (__GNUC__ < 9) && !defined(__clang__)) #define BOOST_MP_THREAD_LOCAL thread_local #define BOOST_MP_USING_THREAD_LOCAL #else #pragma GCC warning "thread_local on mingw is broken, please use MSys mingw gcc-9 or later, see https://sourceforge.net/p/mingw-w64/bugs/527/" #define BOOST_MP_THREAD_LOCAL #endif #ifdef __has_include # if __has_include() # include # ifdef __cpp_lib_is_constant_evaluated # include # define BOOST_MP_HAS_IS_CONSTANT_EVALUATED # endif # endif #endif #ifdef __has_builtin #if __has_builtin(__builtin_is_constant_evaluated) && !defined(BOOST_NO_CXX14_CONSTEXPR) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) #define BOOST_MP_HAS_BUILTIN_IS_CONSTANT_EVALUATED #endif #endif // // MSVC also supports __builtin_is_constant_evaluated if it's recent enough: // #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 192528326) # define BOOST_MP_HAS_BUILTIN_IS_CONSTANT_EVALUATED #endif // // As does GCC-9: // #if defined(BOOST_GCC) && !defined(BOOST_NO_CXX14_CONSTEXPR) && (__GNUC__ >= 9) && !defined(BOOST_MP_HAS_BUILTIN_IS_CONSTANT_EVALUATED) # define BOOST_MP_HAS_BUILTIN_IS_CONSTANT_EVALUATED #endif #if defined(BOOST_MP_HAS_IS_CONSTANT_EVALUATED) && !defined(BOOST_NO_CXX14_CONSTEXPR) # define BOOST_MP_IS_CONST_EVALUATED(x) std::is_constant_evaluated() #elif defined(BOOST_MP_HAS_BUILTIN_IS_CONSTANT_EVALUATED) # define BOOST_MP_IS_CONST_EVALUATED(x) __builtin_is_constant_evaluated() #elif !defined(BOOST_NO_CXX14_CONSTEXPR) && defined(BOOST_GCC) && (__GNUC__ >= 6) # define BOOST_MP_IS_CONST_EVALUATED(x) __builtin_constant_p(x) #else # define BOOST_MP_NO_CONSTEXPR_DETECTION #endif #define BOOST_MP_CXX14_CONSTEXPR BOOST_CXX14_CONSTEXPR // // Early compiler versions trip over the constexpr code: // #if defined(__clang__) && (__clang_major__ < 5) #undef BOOST_MP_CXX14_CONSTEXPR #define BOOST_MP_CXX14_CONSTEXPR #endif #if defined(__apple_build_version__) && (__clang_major__ < 9) #undef BOOST_MP_CXX14_CONSTEXPR #define BOOST_MP_CXX14_CONSTEXPR #endif #if defined(BOOST_GCC) && (__GNUC__ < 6) #undef BOOST_MP_CXX14_CONSTEXPR #define BOOST_MP_CXX14_CONSTEXPR #endif #if defined(BOOST_INTEL) #undef BOOST_MP_CXX14_CONSTEXPR #define BOOST_MP_CXX14_CONSTEXPR #define BOOST_MP_NO_CONSTEXPR_DETECTION #endif #ifdef BOOST_MP_NO_CONSTEXPR_DETECTION # define BOOST_CXX14_CONSTEXPR_IF_DETECTION #else # define BOOST_CXX14_CONSTEXPR_IF_DETECTION constexpr #endif #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable : 6326) #endif namespace boost { namespace multiprecision { enum expression_template_option { et_off = 0, et_on = 1 }; template struct expression_template_default { static constexpr const expression_template_option value = et_on; }; template ::value> class number; template struct is_number : public std::integral_constant {}; template struct is_number > : public std::integral_constant {}; template struct is_et_number : public std::integral_constant {}; template struct is_et_number > : public std::integral_constant {}; template struct is_no_et_number : public std::integral_constant {}; template struct is_no_et_number > : public std::integral_constant {}; namespace detail { // Forward-declare an expression wrapper template struct expression; } // namespace detail template struct is_number_expression : public std::integral_constant {}; template struct is_number_expression > : public std::integral_constant {}; template struct is_compatible_arithmetic_type : public std::integral_constant::value && !std::is_same::value && !is_number_expression::value> {}; namespace detail { // // Workaround for missing abs(boost::long_long_type) and abs(__int128) on some compilers: // template constexpr typename std::enable_if<(boost::multiprecision::detail::is_signed::value || std::is_floating_point::value), T>::type abs(T t) noexcept { // This strange expression avoids a hardware trap in the corner case // that val is the most negative value permitted in boost::long_long_type. // See https://svn.boost.org/trac/boost/ticket/9740. return t < 0 ? T(1u) + T(-(t + 1)) : t; } template constexpr typename std::enable_if::value, T>::type abs(T t) noexcept { return t; } #define BOOST_MP_USING_ABS using boost::multiprecision::detail::abs; template constexpr typename std::enable_if<(boost::multiprecision::detail::is_signed::value || std::is_floating_point::value), typename boost::multiprecision::detail::make_unsigned::type>::type unsigned_abs(T t) noexcept { // This strange expression avoids a hardware trap in the corner case // that val is the most negative value permitted in boost::long_long_type. // See https://svn.boost.org/trac/boost/ticket/9740. return t < 0 ? static_cast::type>(1u) + static_cast::type>(-(t + 1)) : static_cast::type>(t); } template constexpr typename std::enable_if::value, T>::type unsigned_abs(T t) noexcept { return t; } template struct bits_of { static_assert(boost::multiprecision::detail::is_integral::value || std::is_enum::value || std::numeric_limits::is_specialized, "Failed integer size check"); static constexpr const unsigned value = std::numeric_limits::is_specialized ? std::numeric_limits::digits : sizeof(T) * CHAR_BIT - (boost::multiprecision::detail::is_signed::value ? 1 : 0); }; #if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__) #define BOOST_MP_BITS_OF_FLOAT128_DEFINED template <> struct bits_of<__float128> { static constexpr const unsigned value = 113; }; #endif template struct has_enough_bits { template struct type : public std::integral_constant::value >= b> {}; }; template = std::tuple_size::value)> struct find_index_of_large_enough_type { static constexpr int value = bits_of::type>::value >= digits ? i : find_index_of_large_enough_type::value; }; template struct find_index_of_large_enough_type { static constexpr int value = INT_MAX; }; template ::value <= index)> struct dereference_tuple { using type = typename std::tuple_element::type; }; template struct dereference_tuple { using type = Fallback; }; template struct canonical_imp { using type = typename std::remove_cv::type>::type; }; template struct canonical_imp, Backend, Tag> { using type = B; }; template struct canonical_imp, Backend, Tag> { using type = B; }; #ifdef __SUNPRO_CC template struct canonical_imp, Backend, std::integral_constant > { using type = B; }; template struct canonical_imp, Backend, std::integral_constant > { using type = B; }; #endif template struct canonical_imp > { static constexpr int index = find_index_of_large_enough_type::value>::value; using type = typename dereference_tuple::type; }; template struct canonical_imp > { static constexpr int index = find_index_of_large_enough_type::value>::value; using type = typename dereference_tuple::type; }; template struct canonical_imp > { static constexpr int index = find_index_of_large_enough_type::value>::value; using type = typename dereference_tuple::type; }; template struct canonical_imp > { using type = const char*; }; template struct canonical { using tag_type = typename std::conditional< boost::multiprecision::detail::is_signed::value && boost::multiprecision::detail::is_integral::value, std::integral_constant, typename std::conditional< boost::multiprecision::detail::is_unsigned::value, std::integral_constant, typename std::conditional< std::is_floating_point::value, std::integral_constant, typename std::conditional< (std::is_convertible::value || std::is_same::value), std::integral_constant, std::integral_constant >::type>::type>::type>::type; using type = typename canonical_imp::type; }; struct terminal {}; struct negate {}; struct plus {}; struct minus {}; struct multiplies {}; struct divides {}; struct modulus {}; struct shift_left {}; struct shift_right {}; struct bitwise_and {}; struct bitwise_or {}; struct bitwise_xor {}; struct bitwise_complement {}; struct add_immediates {}; struct subtract_immediates {}; struct multiply_immediates {}; struct divide_immediates {}; struct modulus_immediates {}; struct bitwise_and_immediates {}; struct bitwise_or_immediates {}; struct bitwise_xor_immediates {}; struct complement_immediates {}; struct function {}; struct multiply_add {}; struct multiply_subtract {}; template struct backend_type; template struct backend_type > { using type = T; }; template struct backend_type > { using type = typename backend_type::result_type>::type; }; template struct combine_expression { using type = decltype(T1() + T2()); }; template struct combine_expression, T2> { using type = number; }; template struct combine_expression > { using type = number; }; template struct combine_expression, number > { using type = number; }; template struct combine_expression, number > { using type = typename std::conditional< std::is_convertible, number >::value, number, number >::type; }; template struct arg_type { using type = expression; }; template struct arg_type > { using type = expression; }; struct unmentionable { unmentionable* proc() { return 0; } }; typedef unmentionable* (unmentionable::*unmentionable_type)(); template struct expression_storage_base { using type = const T&; }; template struct expression_storage_base { using type = T; }; template struct expression_storage : public expression_storage_base::value> {}; template struct expression_storage { using type = T*; }; template struct expression_storage { using type = const T*; }; template struct expression_storage > { using type = expression; }; template struct expression { using arity = std::integral_constant ; using left_type = typename arg_type::type ; using left_result_type = typename left_type::result_type; using result_type = typename left_type::result_type; using tag_type = tag ; explicit BOOST_MP_CXX14_CONSTEXPR expression(const Arg1& a) : arg(a) {} BOOST_MP_CXX14_CONSTEXPR expression(const expression& e) : arg(e.arg) {} // // If we have static_assert we can give a more useful error message // than if we simply have no operator defined at all: // template BOOST_MP_CXX14_CONSTEXPR expression& operator=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator+=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator-=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator*=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator/=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator%=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator|=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator&=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator^=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator<<=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator>>=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR left_type left() const { return left_type(arg); } BOOST_MP_CXX14_CONSTEXPR const Arg1& left_ref() const noexcept { return arg; } static constexpr const unsigned depth = left_type::depth + 1; template ::value && !std::is_convertible::value && std::is_constructible::value, int>::type = 0 #endif > explicit BOOST_MP_CXX14_CONSTEXPR operator T() const { return static_cast(static_cast(*this)); } BOOST_MP_FORCEINLINE explicit BOOST_MP_CXX14_CONSTEXPR operator bool() const { result_type r(*this); return static_cast(r); } template BOOST_MP_CXX14_CONSTEXPR T convert_to() { result_type r(*this); return r.template convert_to(); } private: typename expression_storage::type arg; expression& operator=(const expression&); }; template struct expression { using arity = std::integral_constant; using result_type = Arg1 ; using tag_type = terminal ; explicit BOOST_MP_CXX14_CONSTEXPR expression(const Arg1& a) : arg(a) {} BOOST_MP_CXX14_CONSTEXPR expression(const expression& e) : arg(e.arg) {} // // If we have static_assert we can give a more useful error message // than if we simply have no operator defined at all: // template BOOST_MP_CXX14_CONSTEXPR expression& operator=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator+=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator-=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator*=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator/=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator%=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator|=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator&=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator^=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator<<=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator>>=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR const Arg1& value() const noexcept { return arg; } static constexpr const unsigned depth = 0; template ::value && !std::is_convertible::value && std::is_constructible::value, int>::type = 0 #endif > explicit BOOST_MP_CXX14_CONSTEXPR operator T() const { return static_cast(static_cast(*this)); } BOOST_MP_FORCEINLINE explicit BOOST_MP_CXX14_CONSTEXPR operator bool() const { result_type r(*this); return static_cast(r); } template BOOST_MP_CXX14_CONSTEXPR T convert_to() { result_type r(*this); return r.template convert_to(); } private: typename expression_storage::type arg; expression& operator=(const expression&); }; template struct expression { using arity = std::integral_constant ; using left_type = typename arg_type::type ; using right_type = typename arg_type::type ; using left_result_type = typename left_type::result_type ; using right_result_type = typename right_type::result_type ; using result_type = typename combine_expression::type; using tag_type = tag ; BOOST_MP_CXX14_CONSTEXPR expression(const Arg1& a1, const Arg2& a2) : arg1(a1), arg2(a2) {} BOOST_MP_CXX14_CONSTEXPR expression(const expression& e) : arg1(e.arg1), arg2(e.arg2) {} // // If we have static_assert we can give a more useful error message // than if we simply have no operator defined at all: // template BOOST_MP_CXX14_CONSTEXPR expression& operator=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator+=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator-=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator*=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator/=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator%=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator|=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator&=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator^=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator<<=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator>>=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR left_type left() const { return left_type(arg1); } BOOST_MP_CXX14_CONSTEXPR right_type right() const { return right_type(arg2); } BOOST_MP_CXX14_CONSTEXPR const Arg1& left_ref() const noexcept { return arg1; } BOOST_MP_CXX14_CONSTEXPR const Arg2& right_ref() const noexcept { return arg2; } template ::value && !std::is_convertible::value && std::is_constructible::value, int>::type = 0 #endif > explicit BOOST_MP_CXX14_CONSTEXPR operator T() const { return static_cast(static_cast(*this)); } BOOST_MP_FORCEINLINE explicit BOOST_MP_CXX14_CONSTEXPR operator bool() const { result_type r(*this); return static_cast(r); } template BOOST_MP_CXX14_CONSTEXPR T convert_to() { result_type r(*this); return r.template convert_to(); } static const constexpr unsigned left_depth = left_type::depth + 1; static const constexpr unsigned right_depth = right_type::depth + 1; static const constexpr unsigned depth = left_depth > right_depth ? left_depth : right_depth; private: typename expression_storage::type arg1; typename expression_storage::type arg2; expression& operator=(const expression&); }; template struct expression { using arity = std::integral_constant ; using left_type = typename arg_type::type ; using middle_type = typename arg_type::type ; using right_type = typename arg_type::type ; using left_result_type = typename left_type::result_type ; using middle_result_type = typename middle_type::result_type; using right_result_type = typename right_type::result_type ; using result_type = typename combine_expression< left_result_type, typename combine_expression::type>::type; using tag_type = tag ; BOOST_MP_CXX14_CONSTEXPR expression(const Arg1& a1, const Arg2& a2, const Arg3& a3) : arg1(a1), arg2(a2), arg3(a3) {} BOOST_MP_CXX14_CONSTEXPR expression(const expression& e) : arg1(e.arg1), arg2(e.arg2), arg3(e.arg3) {} // // If we have static_assert we can give a more useful error message // than if we simply have no operator defined at all: // template BOOST_MP_CXX14_CONSTEXPR expression& operator=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator+=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator-=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator*=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator/=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator%=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator|=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator&=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator^=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator<<=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator>>=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR left_type left() const { return left_type(arg1); } BOOST_MP_CXX14_CONSTEXPR middle_type middle() const { return middle_type(arg2); } BOOST_MP_CXX14_CONSTEXPR right_type right() const { return right_type(arg3); } BOOST_MP_CXX14_CONSTEXPR const Arg1& left_ref() const noexcept { return arg1; } BOOST_MP_CXX14_CONSTEXPR const Arg2& middle_ref() const noexcept { return arg2; } BOOST_MP_CXX14_CONSTEXPR const Arg3& right_ref() const noexcept { return arg3; } template ::value && !std::is_convertible::value && std::is_constructible::value, int>::type = 0 #endif > explicit BOOST_MP_CXX14_CONSTEXPR operator T() const { return static_cast(static_cast(*this)); } BOOST_MP_FORCEINLINE explicit BOOST_MP_CXX14_CONSTEXPR operator bool() const { result_type r(*this); return static_cast(r); } template BOOST_MP_CXX14_CONSTEXPR T convert_to() { result_type r(*this); return r.template convert_to(); } static constexpr const unsigned left_depth = left_type::depth + 1; static constexpr const unsigned middle_depth = middle_type::depth + 1; static constexpr const unsigned right_depth = right_type::depth + 1; static constexpr const unsigned depth = left_depth > right_depth ? (left_depth > middle_depth ? left_depth : middle_depth) : (right_depth > middle_depth ? right_depth : middle_depth); private: typename expression_storage::type arg1; typename expression_storage::type arg2; typename expression_storage::type arg3; expression& operator=(const expression&); }; template struct expression { using arity = std::integral_constant ; using left_type = typename arg_type::type ; using left_middle_type = typename arg_type::type ; using right_middle_type = typename arg_type::type ; using right_type = typename arg_type::type ; using left_result_type = typename left_type::result_type ; using left_middle_result_type = typename left_middle_type::result_type ; using right_middle_result_type = typename right_middle_type::result_type; using right_result_type = typename right_type::result_type ; using result_type = typename combine_expression< left_result_type, typename combine_expression< left_middle_result_type, typename combine_expression::type>::type>::type; using tag_type = tag ; BOOST_MP_CXX14_CONSTEXPR expression(const Arg1& a1, const Arg2& a2, const Arg3& a3, const Arg4& a4) : arg1(a1), arg2(a2), arg3(a3), arg4(a4) {} BOOST_MP_CXX14_CONSTEXPR expression(const expression& e) : arg1(e.arg1), arg2(e.arg2), arg3(e.arg3), arg4(e.arg4) {} // // If we have static_assert we can give a more useful error message // than if we simply have no operator defined at all: // template BOOST_MP_CXX14_CONSTEXPR expression& operator=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not assign to a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator++(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not increment a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--() { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR expression& operator--(int) { // This should always fail: static_assert(sizeof(*this) == INT_MAX, "You can not decrement a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator+=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator+= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator-=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator-= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator*=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator*= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator/=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator/= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator%=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator%= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator|=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator|= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator&=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator&= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator^=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator^= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator<<=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator<<= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } template BOOST_MP_CXX14_CONSTEXPR expression& operator>>=(const Other&) { // This should always fail: static_assert(sizeof(Other) == INT_MAX, "You can not use operator>>= on a Boost.Multiprecision expression template: did you inadvertantly store an expression template in a \"auto\" variable? Or pass an expression to a template function with deduced temnplate arguments?"); return *this; } BOOST_MP_CXX14_CONSTEXPR left_type left() const { return left_type(arg1); } BOOST_MP_CXX14_CONSTEXPR left_middle_type left_middle() const { return left_middle_type(arg2); } BOOST_MP_CXX14_CONSTEXPR right_middle_type right_middle() const { return right_middle_type(arg3); } BOOST_MP_CXX14_CONSTEXPR right_type right() const { return right_type(arg4); } BOOST_MP_CXX14_CONSTEXPR const Arg1& left_ref() const noexcept { return arg1; } BOOST_MP_CXX14_CONSTEXPR const Arg2& left_middle_ref() const noexcept { return arg2; } BOOST_MP_CXX14_CONSTEXPR const Arg3& right_middle_ref() const noexcept { return arg3; } BOOST_MP_CXX14_CONSTEXPR const Arg4& right_ref() const noexcept { return arg4; } template ::value && !std::is_convertible::value && std::is_constructible::value, int>::type = 0 #endif > explicit BOOST_MP_CXX14_CONSTEXPR operator T() const { return static_cast(static_cast(*this)); } BOOST_MP_FORCEINLINE explicit BOOST_MP_CXX14_CONSTEXPR operator bool() const { result_type r(*this); return static_cast(r); } template BOOST_MP_CXX14_CONSTEXPR T convert_to() { result_type r(*this); return r.template convert_to(); } static constexpr const unsigned left_depth = left_type::depth + 1; static constexpr const unsigned left_middle_depth = left_middle_type::depth + 1; static constexpr const unsigned right_middle_depth = right_middle_type::depth + 1; static constexpr const unsigned right_depth = right_type::depth + 1; static constexpr const unsigned left_max_depth = left_depth > left_middle_depth ? left_depth : left_middle_depth; static constexpr const unsigned right_max_depth = right_depth > right_middle_depth ? right_depth : right_middle_depth; static constexpr const unsigned depth = left_max_depth > right_max_depth ? left_max_depth : right_max_depth; private: typename expression_storage::type arg1; typename expression_storage::type arg2; typename expression_storage::type arg3; typename expression_storage::type arg4; expression& operator=(const expression&); }; template struct digits2 { static_assert(std::numeric_limits::is_specialized, "numeric_limits must be specialized here"); static_assert((std::numeric_limits::radix == 2) || (std::numeric_limits::radix == 10), "Failed radix check"); // If we really have so many digits that this fails, then we're probably going to hit other problems anyway: static_assert(LONG_MAX / 1000 > (std::numeric_limits::digits + 1), "Too many digits to cope with here"); static constexpr const long m_value = std::numeric_limits::radix == 10 ? (((std::numeric_limits::digits + 1) * 1000L) / 301L) : std::numeric_limits::digits; static inline constexpr long value() noexcept { return m_value; } }; #ifndef BOOST_MP_MIN_EXPONENT_DIGITS #ifdef _MSC_VER #define BOOST_MP_MIN_EXPONENT_DIGITS 2 #else #define BOOST_MP_MIN_EXPONENT_DIGITS 2 #endif #endif template void format_float_string(S& str, std::intmax_t my_exp, std::intmax_t digits, std::ios_base::fmtflags f, bool iszero) { using size_type = typename S::size_type; bool scientific = (f & std::ios_base::scientific) == std::ios_base::scientific; bool fixed = (f & std::ios_base::fixed) == std::ios_base::fixed; bool showpoint = (f & std::ios_base::showpoint) == std::ios_base::showpoint; bool showpos = (f & std::ios_base::showpos) == std::ios_base::showpos; bool neg = str.size() && (str[0] == '-'); if (neg) str.erase(0, 1); if (digits == 0) { digits = (std::max)(str.size(), size_type(16)); } if (iszero || str.empty() || (str.find_first_not_of('0') == S::npos)) { // We will be printing zero, even though the value might not // actually be zero (it just may have been rounded to zero). str = "0"; if (scientific || fixed) { str.append(1, '.'); str.append(size_type(digits), '0'); if (scientific) str.append("e+00"); } else { if (showpoint) { str.append(1, '.'); if (digits > 1) str.append(size_type(digits - 1), '0'); } } if (neg) str.insert(static_cast(0), 1, '-'); else if (showpos) str.insert(static_cast(0), 1, '+'); return; } if (!fixed && !scientific && !showpoint) { // // Suppress trailing zeros: // std::string::iterator pos = str.end(); while (pos != str.begin() && *--pos == '0') { } if (pos != str.end()) ++pos; str.erase(pos, str.end()); if (str.empty()) str = '0'; } else if (!fixed || (my_exp >= 0)) { // // Pad out the end with zero's if we need to: // std::intmax_t chars = str.size(); chars = digits - chars; if (scientific) ++chars; if (chars > 0) { str.append(static_cast(chars), '0'); } } if (fixed || (!scientific && (my_exp >= -4) && (my_exp < digits))) { if (1 + my_exp > static_cast(str.size())) { // Just pad out the end with zeros: str.append(static_cast(1 + my_exp - str.size()), '0'); if (showpoint || fixed) str.append("."); } else if (my_exp + 1 < static_cast(str.size())) { if (my_exp < 0) { str.insert(static_cast(0), static_cast(-1 - my_exp), '0'); str.insert(static_cast(0), "0."); } else { // Insert the decimal point: str.insert(static_cast(my_exp + 1), 1, '.'); } } else if (showpoint || fixed) // we have exactly the digits we require to left of the point str += "."; if (fixed) { // We may need to add trailing zeros: std::intmax_t l = str.find('.') + 1; l = digits - (str.size() - l); if (l > 0) str.append(size_type(l), '0'); } } else { BOOST_MP_USING_ABS // Scientific format: if (showpoint || (str.size() > 1)) str.insert(static_cast(1u), 1, '.'); str.append(static_cast(1u), 'e'); S e = boost::lexical_cast(abs(my_exp)); if (e.size() < BOOST_MP_MIN_EXPONENT_DIGITS) e.insert(static_cast(0), BOOST_MP_MIN_EXPONENT_DIGITS - e.size(), '0'); if (my_exp < 0) e.insert(static_cast(0), 1, '-'); else e.insert(static_cast(0), 1, '+'); str.append(e); } if (neg) str.insert(static_cast(0), 1, '-'); else if (showpos) str.insert(static_cast(0), 1, '+'); } template BOOST_MP_CXX14_CONSTEXPR void check_shift_range(V val, const std::integral_constant&, const std::integral_constant&) { if (val > (std::numeric_limits::max)()) BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a value greater than std::numeric_limits::max().")); if (val < 0) BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a negative value.")); } template BOOST_MP_CXX14_CONSTEXPR void check_shift_range(V val, const std::integral_constant&, const std::integral_constant&) { if (val < 0) BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a negative value.")); } template BOOST_MP_CXX14_CONSTEXPR void check_shift_range(V val, const std::integral_constant&, const std::integral_constant&) { if (val > (std::numeric_limits::max)()) BOOST_THROW_EXCEPTION(std::out_of_range("Can not shift by a value greater than std::numeric_limits::max().")); } template BOOST_MP_CXX14_CONSTEXPR void check_shift_range(V, const std::integral_constant&, const std::integral_constant&) noexcept {} template BOOST_MP_CXX14_CONSTEXPR const T& evaluate_if_expression(const T& val) { return val; } template BOOST_MP_CXX14_CONSTEXPR typename expression::result_type evaluate_if_expression(const expression& val) { return val; } } // namespace detail // // Traits class, lets us know what kind of number we have, defaults to a floating point type: // enum number_category_type { number_kind_unknown = -1, number_kind_integer = 0, number_kind_floating_point = 1, number_kind_rational = 2, number_kind_fixed_point = 3, number_kind_complex = 4 }; template struct number_category_base : public std::integral_constant {}; template struct number_category_base : public std::integral_constant::is_integer ? number_kind_integer : (std::numeric_limits::max_exponent ? number_kind_floating_point : number_kind_unknown)> {}; template struct number_category : public number_category_base::value || boost::multiprecision::detail::is_arithmetic::value, std::is_abstract::value> {}; template struct number_category > : public number_category {}; template struct number_category > : public number_category::result_type> {}; // // Specializations for types which do not always have numberic_limits specializations: // #ifdef BOOST_HAS_INT128 template <> struct number_category : public std::integral_constant {}; template <> struct number_category : public std::integral_constant {}; #endif #ifdef BOOST_HAS_FLOAT128 template <> struct number_category<__float128> : public std::integral_constant {}; #endif template struct component_type { using type = T; }; template struct component_type > : public component_type::result_type> {}; template struct scalar_result_from_possible_complex { using type = typename std::conditional::value == number_kind_complex, typename component_type::type, T>::type; }; template struct complex_result_from_scalar; // individual backends must specialize this trait. template struct is_unsigned_number : public std::integral_constant {}; template struct is_unsigned_number > : public is_unsigned_number {}; template struct is_signed_number : public std::integral_constant::value> {}; template struct is_interval_number : public std::integral_constant {}; template struct is_interval_number > : public is_interval_number {}; template struct is_equivalent_number_type : public std::is_same {}; template struct is_equivalent_number_type, T2> : public is_equivalent_number_type {}; template struct is_equivalent_number_type > : public is_equivalent_number_type {}; template struct is_equivalent_number_type, number > : public is_equivalent_number_type {}; } } // namespace boost namespace boost { namespace math { namespace tools { template struct promote_arg; template struct promote_arg > { using type = typename boost::multiprecision::detail::expression::result_type; }; template inline R real_cast(const boost::multiprecision::number& val) { return val.template convert_to(); } template inline R real_cast(const boost::multiprecision::detail::expression& val) { using val_type = typename boost::multiprecision::detail::expression::result_type; return val_type(val).template convert_to(); } template struct is_complex_type > : public std::integral_constant::value == boost::multiprecision::number_kind_complex> {}; } // namespace tools namespace constants { template struct is_explicitly_convertible_from_string; template struct is_explicitly_convertible_from_string > { static constexpr const bool value = true; }; } // namespace constants }} // namespace boost::math #ifdef BOOST_MSVC #pragma warning(pop) #endif #endif // BOOST_MATH_BIG_NUM_BASE_HPP