Added thirdparty: boost library

This commit is contained in:
Viacheslav Demydiuk
2024-01-06 19:55:56 +02:00
parent bf49f439e1
commit bccd1e7051
15683 changed files with 3239840 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
// (C) Copyright Matt Borland 2021.
// Use, modification and distribution are subject to 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)
//
// We deliberately use assert in here:
//
// boost-no-inspect
#ifndef BOOST_MP_DETAIL_ASSERT_HPP
#define BOOST_MP_DETAIL_ASSERT_HPP
#include <boost/multiprecision/detail/standalone_config.hpp>
#ifndef BOOST_MP_STANDALONE
#include <boost/assert.hpp>
#define BOOST_MP_ASSERT(expr) BOOST_ASSERT(expr)
#define BOOST_MP_ASSERT_MSG(expr, msg) BOOST_ASSERT_MSG(expr, msg)
#else // Standalone mode - use cassert
#include <cassert>
#define BOOST_MP_ASSERT(expr) assert(expr)
#define BOOST_MP_ASSERT_MSG(expr, msg) assert((expr)&&(msg))
#endif
#endif // BOOST_MP_DETAIL_ASSERT_HPP
+62
View File
@@ -0,0 +1,62 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2017 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_MP_DETAIL_ATOMIC_HPP
#define BOOST_MP_DETAIL_ATOMIC_HPP
#include <boost/multiprecision/detail/standalone_config.hpp>
#ifdef BOOST_HAS_THREADS
# include <atomic>
# define BOOST_MATH_ATOMIC_NS std
namespace boost {
namespace multiprecision {
namespace detail {
#if ATOMIC_INT_LOCK_FREE == 2
using atomic_counter_type = std::atomic<int>;
using atomic_unsigned_type = std::atomic<unsigned>;
using atomic_integer_type = int;
using atomic_unsigned_integer_type = unsigned;
#elif ATOMIC_SHORT_LOCK_FREE == 2
using atomic_counter_type = std::atomic<short>;
using atomic_unsigned_type = std::atomic<unsigned short>;
using atomic_integer_type = short;
using atomic_unsigned_integer_type = unsigned short;
#elif ATOMIC_LONG_LOCK_FREE == 2
using atomic_unsigned_integer_type = std::atomic<long>;
using atomic_unsigned_type = std::atomic<unsigned long>;
using atomic_unsigned_integer_type = unsigned long;
using atomic_integer_type = long;
#elif ATOMIC_LLONG_LOCK_FREE == 2
using atomic_unsigned_integer_type = std::atomic<long long>;
using atomic_unsigned_type = std::atomic<unsigned long long>;
using atomic_integer_type = long long;
using atomic_unsigned_integer_type = unsigned long long;
#else
#define BOOST_MT_NO_ATOMIC_INT
#endif
}
}}
#else // BOOST_HAS_THREADS
#define BOOST_MT_NO_ATOMIC_INT
#endif // BOOST_HAS_THREADS
namespace boost { namespace multiprecision { namespace detail {
#ifdef BOOST_MT_NO_ATOMIC_INT
using precision_type = unsigned;
#else
using precision_type = atomic_unsigned_type;
#endif
} } }
#endif // BOOST_MP_DETAIL_ATOMIC_HPP
+317
View File
@@ -0,0 +1,317 @@
///////////////////////////////////////////////////////////////
// Copyright 2013 John Maddock. 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
//
// Comparison operators for cpp_int_backend:
//
#ifndef BOOST_MP_DETAIL_BITSCAN_HPP
#define BOOST_MP_DETAIL_BITSCAN_HPP
#include <cstdint>
#include <climits>
#include <type_traits>
#include <boost/multiprecision/detail/endian.hpp>
#include <boost/multiprecision/detail/standalone_config.hpp>
#if (defined(BOOST_MSVC) || (defined(__clang__) && defined(__c2__)) || (defined(BOOST_INTEL) && defined(_MSC_VER))) && (defined(_M_IX86) || defined(_M_X64))
#include <intrin.h>
#endif
namespace boost { namespace multiprecision { namespace detail {
template <class Unsigned>
inline BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb_default(Unsigned mask)
{
std::size_t result = 0;
while (!(mask & 1u))
{
mask >>= 1;
++result;
}
return result;
}
template <class Unsigned>
inline BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb_default(Unsigned mask)
{
std::size_t index = 0;
while (mask)
{
++index;
mask >>= 1;
}
return --index;
}
template <class Unsigned>
inline BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask, const std::integral_constant<int, 0>&)
{
return find_lsb_default(mask);
}
template <class Unsigned>
inline BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask, const std::integral_constant<int, 0>&)
{
return find_msb_default(mask);
}
#if (defined(BOOST_MSVC) || (defined(__clang__) && defined(__c2__)) || (defined(BOOST_INTEL) && defined(_MSC_VER))) && (defined(_M_IX86) || defined(_M_X64))
#pragma intrinsic(_BitScanForward, _BitScanReverse)
BOOST_FORCEINLINE std::size_t find_lsb(unsigned long mask, const std::integral_constant<int, 1>&)
{
unsigned long result;
_BitScanForward(&result, mask);
return result;
}
BOOST_FORCEINLINE std::size_t find_msb(unsigned long mask, const std::integral_constant<int, 1>&)
{
unsigned long result;
_BitScanReverse(&result, mask);
return result;
}
#ifdef _M_X64
#pragma intrinsic(_BitScanForward64, _BitScanReverse64)
BOOST_FORCEINLINE std::size_t find_lsb(unsigned __int64 mask, const std::integral_constant<int, 2>&)
{
unsigned long result;
_BitScanForward64(&result, mask);
return result;
}
template <class Unsigned>
BOOST_FORCEINLINE std::size_t find_msb(Unsigned mask, const std::integral_constant<int, 2>&)
{
unsigned long result;
_BitScanReverse64(&result, mask);
return result;
}
#endif
template <class Unsigned>
BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask)
{
using ui_type = typename boost::multiprecision::detail::make_unsigned<Unsigned>::type;
using tag_type = typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned long),
std::integral_constant<int, 1>,
#ifdef _M_X64
typename std::conditional<
sizeof(Unsigned) <= sizeof(__int64),
std::integral_constant<int, 2>,
std::integral_constant<int, 0> >::type
#else
std::integral_constant<int, 0>
#endif
>::type;
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(mask))
{
return find_lsb_default(mask);
}
else
#endif
return find_lsb(static_cast<ui_type>(mask), tag_type());
}
template <class Unsigned>
BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask)
{
using ui_type = typename boost::multiprecision::detail::make_unsigned<Unsigned>::type;
using tag_type = typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned long),
std::integral_constant<int, 1>,
#ifdef _M_X64
typename std::conditional<
sizeof(Unsigned) <= sizeof(__int64),
std::integral_constant<int, 2>,
std::integral_constant<int, 0> >::type
#else
std::integral_constant<int, 0>
#endif
>::type;
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(mask))
{
return find_msb_default(mask);
}
else
#endif
return find_msb(static_cast<ui_type>(mask), tag_type());
}
#elif defined(BOOST_GCC) || defined(__clang__) || (defined(BOOST_INTEL) && defined(__GNUC__))
BOOST_FORCEINLINE std::size_t find_lsb(std::size_t mask, std::integral_constant<int, 1> const&)
{
return static_cast<std::size_t>(__builtin_ctz(static_cast<unsigned int>(mask)));
}
BOOST_FORCEINLINE std::size_t find_lsb(unsigned long mask, std::integral_constant<int, 2> const&)
{
return static_cast<std::size_t>(__builtin_ctzl(static_cast<unsigned long>(mask)));
}
BOOST_FORCEINLINE std::size_t find_lsb(unsigned long long mask, std::integral_constant<int, 3> const&)
{
return static_cast<std::size_t>(__builtin_ctzll(static_cast<unsigned long long>(mask)));
}
BOOST_FORCEINLINE std::size_t find_msb(std::size_t mask, std::integral_constant<int, 1> const&)
{
return static_cast<std::size_t>(static_cast<std::size_t>(sizeof(unsigned) * static_cast<std::size_t>(CHAR_BIT) - 1u) - static_cast<std::size_t>(__builtin_clz(static_cast<unsigned int>(mask))));
}
BOOST_FORCEINLINE std::size_t find_msb(unsigned long mask, std::integral_constant<int, 2> const&)
{
return static_cast<std::size_t>(static_cast<std::size_t>(sizeof(unsigned long) * static_cast<std::size_t>(CHAR_BIT) - 1u) - static_cast<std::size_t>(__builtin_clzl(static_cast<unsigned long>(mask))));
}
BOOST_FORCEINLINE std::size_t find_msb(unsigned long long mask, std::integral_constant<int, 3> const&)
{
return static_cast<std::size_t>(static_cast<std::size_t>(sizeof(unsigned long long) * static_cast<std::size_t>(CHAR_BIT) - 1u) - static_cast<std::size_t>(__builtin_clzll(static_cast<unsigned long long>(mask))));
}
#ifdef BOOST_HAS_INT128
BOOST_FORCEINLINE std::size_t find_msb(uint128_type mask, std::integral_constant<int, 0> const&)
{
union
{
uint128_type v;
std::uint64_t sv[2];
} val;
val.v = mask;
#if BOOST_MP_ENDIAN_LITTLE_BYTE
if (val.sv[1])
return find_msb(val.sv[1], std::integral_constant<int, 3>()) + 64;
return find_msb(val.sv[0], std::integral_constant<int, 3>());
#else
if (val.sv[0])
return find_msb(val.sv[0], std::integral_constant<int, 3>()) + 64;
return find_msb(val.sv[1], std::integral_constant<int, 3>());
#endif
}
BOOST_FORCEINLINE std::size_t find_lsb(uint128_type mask, std::integral_constant<int, 0> const&)
{
union
{
uint128_type v;
std::uint64_t sv[2];
} val;
val.v = mask;
#if BOOST_MP_ENDIAN_LITTLE_BYTE
if (val.sv[0] == 0)
return find_lsb(val.sv[1], std::integral_constant<int, 3>()) + 64;
return find_lsb(val.sv[0], std::integral_constant<int, 3>());
#else
if (val.sv[1] == 0)
return find_lsb(val.sv[0], std::integral_constant<int, 3>()) + 64;
return find_lsb(val.sv[1], std::integral_constant<int, 3>());
#endif
}
#endif
template <class Unsigned>
BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask)
{
using ui_type = typename boost::multiprecision::detail::make_unsigned<Unsigned>::type;
using tag_type = typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned),
std::integral_constant<int, 1>,
typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned long),
std::integral_constant<int, 2>,
typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned long long),
std::integral_constant<int, 3>,
std::integral_constant<int, 0> >::type>::type>::type;
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(mask))
{
return find_lsb_default(mask);
}
else
#endif
return find_lsb(static_cast<ui_type>(mask), tag_type());
}
template <class Unsigned>
BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask)
{
using ui_type = typename boost::multiprecision::detail::make_unsigned<Unsigned>::type;
using tag_type = typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned),
std::integral_constant<int, 1>,
typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned long),
std::integral_constant<int, 2>,
typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned long long),
std::integral_constant<int, 3>,
std::integral_constant<int, 0> >::type>::type>::type;
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(mask))
{
return find_msb_default(mask);
}
else
#endif
return find_msb(static_cast<ui_type>(mask), tag_type());
}
#elif defined(BOOST_INTEL)
BOOST_FORCEINLINE std::size_t find_lsb(std::size_t mask, std::integral_constant<int, 1> const&)
{
return _bit_scan_forward(mask);
}
BOOST_FORCEINLINE std::size_t find_msb(std::size_t mask, std::integral_constant<int, 1> const&)
{
return _bit_scan_reverse(mask);
}
template <class Unsigned>
BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask)
{
using ui_type = typename boost::multiprecision::detail::make_unsigned<Unsigned>::type;
using tag_type = typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned),
std::integral_constant<int, 1>,
std::integral_constant<int, 0> >::type;
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(mask))
{
return find_lsb_default(mask);
}
else
#endif
return find_lsb(static_cast<ui_type>(mask), tag_type());
}
template <class Unsigned>
BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask)
{
using ui_type = typename boost::multiprecision::detail::make_unsigned<Unsigned>::type;
using tag_type = typename std::conditional<
sizeof(Unsigned) <= sizeof(unsigned),
std::integral_constant<int, 1>,
std::integral_constant<int, 0> >::type;
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(mask))
{
return find_msb_default(mask);
}
else
#endif
return find_msb(static_cast<ui_type>(mask), tag_type());
}
#else
template <class Unsigned>
BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_lsb(Unsigned mask)
{
return find_lsb(mask, std::integral_constant<int, 0>());
}
template <class Unsigned>
BOOST_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR std::size_t find_msb(Unsigned mask)
{
return find_msb(mask, std::integral_constant<int, 0>());
}
#endif
}}} // namespace boost::multiprecision::detail
#endif
+64
View File
@@ -0,0 +1,64 @@
///////////////////////////////////////////////////////////////////////////////
// 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_MP_CHECK_CPP11_CONFIG_HPP
#define BOOST_MP_CHECK_CPP11_CONFIG_HPP
//
// 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
#endif // BOOST_MP_CHECK_CPP11_CONFIG_HPP
+88
View File
@@ -0,0 +1,88 @@
///////////////////////////////////////////////////////////////
// Copyright 2019 John Maddock. 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_DETAIL_CONSTEXPR_HPP
#define BOOST_MP_DETAIL_CONSTEXPR_HPP
#include <cstring>
#include <boost/multiprecision/detail/standalone_config.hpp>
namespace boost {
namespace multiprecision {
namespace std_constexpr {
template <class T>
inline BOOST_CXX14_CONSTEXPR void swap(T& a, T& b)
{
T t(a);
a = b;
b = t;
}
template <class InputIterator, class OutputIterator>
inline BOOST_CXX14_CONSTEXPR OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
{
//
// There are 3 branches here, only one of which is selected at compile time:
//
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(*first))
{
// constexpr safe code, never generates runtime code:
while (first != last)
{
*result = *first;
++first;
++result;
}
return result;
}
else
#endif
{
#ifndef BOOST_NO_CXX17_IF_CONSTEXPR
if constexpr (std::is_pointer<InputIterator>::value && std::is_pointer<OutputIterator>::value && std::is_trivially_copyable<typename std::remove_reference<decltype(*first)>::type>::value)
{
// The normal runtime branch:
std::memcpy(result, first, static_cast<std::size_t>(static_cast<std::size_t>(last - first) * sizeof(*first)));
return result + (last - first);
}
else
#endif
{
// Alternate runtime branch:
while (first != last)
{
*result = *first;
++first;
++result;
}
return result;
}
}
}
template <class I>
inline BOOST_CXX14_CONSTEXPR bool equal(const I* first, const I* last, const I* other)
{
while (first != last)
{
if (*first != *other)
return false;
++first;
++other;
}
return true;
}
}
}
} // namespace boost::multiprecision::std_constexpr
#endif
File diff suppressed because it is too large Load Diff
+49
View File
@@ -0,0 +1,49 @@
///////////////////////////////////////////////////////////////
// Copyright 2012 John Maddock. 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_DETAIL_DIGITS_HPP
#define BOOST_MP_DETAIL_DIGITS_HPP
namespace boost { namespace multiprecision { namespace detail {
inline constexpr unsigned long digits10_2_2(unsigned long d10)
{
return (d10 * 1000uL) / 301uL + ((d10 * 1000uL) % 301 ? 2u : 1u);
}
inline constexpr unsigned long digits2_2_10(unsigned long d2)
{
return (d2 * 301uL) / 1000uL;
}
#if ULONG_MAX != SIZE_MAX
inline constexpr std::size_t digits10_2_2(std::size_t d10)
{
return (d10 * 1000uL) / 301uL + ((d10 * 1000uL) % 301 ? 2u : 1u);
}
inline constexpr std::size_t digits2_2_10(std::size_t d2)
{
return (d2 * 301uL) / 1000uL;
}
template <class I>
inline constexpr typename std::enable_if<sizeof(I) <= sizeof(unsigned long), unsigned long>::type digits10_2_2(I d10)
{
return digits10_2_2(static_cast<unsigned long>(d10));
}
template <class I>
inline constexpr typename std::enable_if<sizeof(I) <= sizeof(unsigned long), unsigned long>::type digits2_2_10(I d10)
{
return digits2_2_10(static_cast<unsigned long>(d10));
}
#endif
}}} // namespace boost::multiprecision::detail
#endif
+44
View File
@@ -0,0 +1,44 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2012 John Maddock.
// Copyright Christopher Kormanyos 2013. 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_MP_DETAIL_DYNAMIC_ARRAY_HPP
#define BOOST_MP_DETAIL_DYNAMIC_ARRAY_HPP
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <vector>
#include <boost/multiprecision/detail/rebind.hpp>
namespace boost { namespace multiprecision { namespace backends { namespace detail {
template <class ValueType, const std::uint32_t ElemNumber, class my_allocator>
struct dynamic_array : public std::vector<ValueType, typename rebind<ValueType, my_allocator>::type>
{
private:
using base_class_type = std::vector<ValueType, typename rebind<ValueType, my_allocator>::type>;
public:
dynamic_array()
: base_class_type(static_cast<typename base_class_type::size_type>(ElemNumber),
static_cast<typename base_class_type::value_type>(0u)) { }
dynamic_array(std::initializer_list<std::uint32_t> lst)
: base_class_type(static_cast<typename base_class_type::size_type>(ElemNumber),
static_cast<typename base_class_type::value_type>(0u))
{
std::copy(lst.begin(),
lst.begin() + (std::min)(std::size_t(lst.size()), std::size_t(ElemNumber)),
data());
}
typename base_class_type::value_type* data() { return &(*(this->begin())); }
const typename base_class_type::value_type* data() const { return &(*(this->begin())); }
};
}}}} // namespace boost::multiprecision::backends::detail
#endif // BOOST_MP_DETAIL_DYNAMIC_ARRAY_HPP
+87
View File
@@ -0,0 +1,87 @@
/////////////////////////////////////////////////////////////////////
// Copyright 2018 Glen Joseph Fernandes.
// 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_DETAIL_EMPTY_VALUE_HPP
#define BOOST_MP_DETAIL_EMPTY_VALUE_HPP
#include <utility>
#include <boost/multiprecision/detail/standalone_config.hpp>
#if defined(BOOST_GCC_VERSION) && (BOOST_GCC_VERSION >= 40700)
#define BOOST_DETAIL_EMPTY_VALUE_BASE
#elif defined(BOOST_INTEL) && defined(_MSC_VER) && (_MSC_VER >= 1800)
#define BOOST_DETAIL_EMPTY_VALUE_BASE
#elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1800)
#define BOOST_DETAIL_EMPTY_VALUE_BASE
#elif defined(BOOST_CLANG) && !defined(__CUDACC__)
#if __has_feature(is_empty) && __has_feature(is_final)
#define BOOST_DETAIL_EMPTY_VALUE_BASE
#endif
#endif
namespace boost { namespace multiprecision { namespace detail {
template <typename T>
struct use_empty_value_base
{
#if defined(BOOST_DETAIL_EMPTY_VALUE_BASE)
static constexpr bool value = __is_empty(T) && !__is_final(T);
#else
static constexpr bool value = false;
#endif
};
struct empty_init_t {};
namespace empty_impl {
template <typename T, unsigned N = 0,
bool E = boost::multiprecision::detail::use_empty_value_base<T>::value>
class empty_value
{
private:
T value_;
public:
using type = T;
empty_value() = default;
explicit empty_value(boost::multiprecision::detail::empty_init_t) : value_ {} {}
template <typename U, typename... Args>
empty_value(boost::multiprecision::detail::empty_init_t, U&& value, Args&&... args) :
value_ {std::forward<U>(value), std::forward<Args>(args)...} {}
const T& get() const noexcept { return value_; }
T& get() noexcept { return value_; }
};
template <typename T, unsigned N>
class empty_value<T, N, true> : T
{
public:
using type = T;
empty_value() = default;
explicit empty_value(boost::multiprecision::detail::empty_init_t) : T{} {}
template <typename U, typename... Args>
empty_value(boost::multiprecision::detail::empty_init_t, U&& value, Args&&... args) :
T{std::forward<U>(value), std::forward<Args>(args)...} {}
const T& get() const noexcept { return *this; }
T& get() noexcept { return *this; }
};
} // Namespace empty impl
using empty_impl::empty_value;
BOOST_INLINE_CONSTEXPR empty_init_t empty_init = empty_init_t();
}}} // Namespaces
#endif // BOOST_MP_DETAIL_EMPTY_VALUE_HPP
+35
View File
@@ -0,0 +1,35 @@
////////////////////////////////////////////////////////////////
// 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_DETAIL_ENDIAN_HPP
#define BOOST_MP_DETAIL_ENDIAN_HPP
#include <boost/multiprecision/detail/standalone_config.hpp>
#ifndef BOOST_MP_STANDALONE
# include <boost/predef/other/endian.h>
# define BOOST_MP_ENDIAN_BIG_BYTE BOOST_ENDIAN_BIG_BYTE
# define BOOST_MP_ENDIAN_LITTLE_BYTE BOOST_ENDIAN_LITTLE_BYTE
#elif defined(_WIN32)
# define BOOST_MP_ENDIAN_BIG_BYTE 0
# define BOOST_MP_ENDIAN_LITTLE_BYTE 1
#elif defined(__BYTE_ORDER__)
# define BOOST_MP_ENDIAN_BIG_BYTE (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
# define BOOST_MP_ENDIAN_LITTLE_BYTE (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#else
# error Could not determine endian type. Please disable standalone mode, and file an issue at https://github.com/boostorg/multiprecision
#endif // Determine endianness
static_assert((BOOST_MP_ENDIAN_BIG_BYTE || BOOST_MP_ENDIAN_LITTLE_BYTE)
&& !(BOOST_MP_ENDIAN_BIG_BYTE && BOOST_MP_ENDIAN_LITTLE_BYTE),
"Inconsistent endianness detected. Please disable standalone mode, and file an issue at https://github.com/boostorg/multiprecision");
#endif // BOOST_MP_DETAIL_ENDIAN_HPP
File diff suppressed because it is too large Load Diff
+95
View File
@@ -0,0 +1,95 @@
// (C) Copyright John Maddock 2021.
// Use, modification and distribution are subject to 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)
//
// We deliberately use assert in here:
//
#ifndef BOOST_MP_DETAIL_FLOAT128_FUNCTIONS_HPP
#define BOOST_MP_DETAIL_FLOAT128_FUNCTIONS_HPP
#include <boost/multiprecision/detail/standalone_config.hpp>
#ifndef BOOST_MP_STANDALONE
#include <boost/cstdfloat.hpp>
#if defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_CSTDFLOAT_NO_LIBQUADMATH_SUPPORT)
# define BOOST_MP_HAVE_CSTDFLOAT
#endif
#endif
#if defined(BOOST_HAS_FLOAT128)
namespace boost
{
namespace multiprecision
{
namespace float128_procs
{
extern "C" __float128 ldexpq(__float128, int) throw();
extern "C" __float128 frexpq(__float128, int*) throw();
extern "C" __float128 floorq(__float128) throw();
extern "C" __float128 nextafterq(__float128, __float128) throw();
extern "C" int isinfq(__float128) throw();
extern "C" int isnanq(__float128) throw();
extern "C" __float128 strtoflt128(const char*, char**) throw();
#ifdef BOOST_MP_HAVE_CSTDFLOAT
using std::ldexp;
using std::frexp;
using std::floor;
using std::nextafter;
#else
inline __float128 ldexp(__float128 f, int i) throw() { return ldexpq(f, i); }
inline __float128 frexp(__float128 f, int* p) throw() { return frexpq(f, p); }
inline __float128 floor(__float128 f) throw() { return floorq(f); }
inline __float128 nextafter(__float128 a, __float128 b) throw() { return nextafterq(a, b); }
#endif
}
namespace detail {
template <class T>
struct is_float128 : public std::is_same<__float128, T>
{};
}
}
}
namespace boost {
namespace math {
inline __float128 float_next(const __float128& f)
{
return boost::multiprecision::float128_procs::nextafterq(f, 2 * f);
}
inline int (isinf)(const __float128& f)
{
return boost::multiprecision::float128_procs::isinfq(f);
}
inline int (isnan)(const __float128& f)
{
return boost::multiprecision::float128_procs::isnanq(f);
}
}}
#define BOOST_MP_FLOAT128_USING using boost::multiprecision::float128_procs::ldexp; using boost::multiprecision::float128_procs::frexp; using boost::multiprecision::float128_procs::floor; using boost::multiprecision::float128_procs::nextafter; using boost::math::isinf; using boost::math::isnan;
#else
#define BOOST_MP_FLOAT128_USING
namespace boost {
namespace multiprecision {
namespace detail {
template <class T>
struct is_float128 : public std::false_type
{};
}}} // namespace boost::multiprecision::detail
#endif
#endif // BOOST_MP_DETAIL_FLOAT128_FUNCTIONS_HPP
+333
View File
@@ -0,0 +1,333 @@
///////////////////////////////////////////////////////////////
// Copyright 2013 John Maddock. 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
//
// Generic routines for converting floating point values to and from decimal strings.
// Note that these use "naive" algorithms which result in rounding error - so they
// do not round trip to and from the string representation (but should only be out
// in the last bit).
//
#ifndef BOOST_MP_FLOAT_STRING_CVT_HPP
#define BOOST_MP_FLOAT_STRING_CVT_HPP
#include <string>
#include <cctype>
#include <boost/multiprecision/detail/no_exceptions_support.hpp>
#include <boost/multiprecision/detail/assert.hpp>
namespace boost { namespace multiprecision { namespace detail {
template <class I>
inline void round_string_up_at(std::string& s, std::ptrdiff_t pos, I& expon)
{
//
// Rounds up a string representation of a number at pos:
//
if (pos < 0)
{
s.insert(static_cast<std::string::size_type>(0), 1, '1');
s.erase(s.size() - 1);
++expon;
}
else if (s[static_cast<std::size_t>(pos)] == '9')
{
s[static_cast<std::size_t>(pos)] = '0';
round_string_up_at(s, pos - 1, expon);
}
else
{
if ((pos == 0) && (s[static_cast<std::size_t>(pos)] == '0') && (s.size() == 1))
++expon;
++s[static_cast<std::size_t>(pos)];
}
}
template <class Backend>
std::string convert_to_string(Backend b, std::streamsize digits, std::ios_base::fmtflags f)
{
using default_ops::eval_convert_to;
using default_ops::eval_divide;
using default_ops::eval_floor;
using default_ops::eval_fpclassify;
using default_ops::eval_log10;
using default_ops::eval_multiply;
using default_ops::eval_pow;
using default_ops::eval_subtract;
using ui_type = typename std::tuple_element<0, typename Backend::unsigned_types>::type;
using exponent_type = typename Backend::exponent_type ;
std::string result;
bool iszero = false;
bool isneg = false;
exponent_type expon = 0;
std::streamsize org_digits = digits;
BOOST_MP_ASSERT(digits > 0);
int fpt = eval_fpclassify(b);
if (fpt == static_cast<int>(FP_ZERO))
{
result = "0";
iszero = true;
}
else if (fpt == static_cast<int>(FP_INFINITE))
{
if (b.compare(ui_type(0)) < 0)
return "-inf";
else
return ((f & std::ios_base::showpos) == std::ios_base::showpos) ? "+inf" : "inf";
}
else if (fpt == static_cast<int>(FP_NAN))
{
return "nan";
}
else
{
//
// Start by figuring out the exponent:
//
isneg = b.compare(ui_type(0)) < 0;
if (isneg)
b.negate();
Backend t;
Backend ten;
ten = ui_type(10);
eval_log10(t, b);
eval_floor(t, t);
eval_convert_to(&expon, t);
if (-expon > std::numeric_limits<number<Backend> >::max_exponent10 - 3)
{
int e = -expon / 2;
Backend t2;
eval_pow(t2, ten, e);
eval_multiply(t, t2, b);
eval_multiply(t, t2);
if (expon & 1)
eval_multiply(t, ten);
}
else
{
eval_pow(t, ten, -expon);
eval_multiply(t, b);
}
//
// Make sure we're between [1,10) and adjust if not:
//
if (t.compare(ui_type(1)) < 0)
{
eval_multiply(t, ui_type(10));
--expon;
}
else if (t.compare(ui_type(10)) >= 0)
{
eval_divide(t, ui_type(10));
++expon;
}
Backend digit;
ui_type cdigit;
//
// Adjust the number of digits required based on formatting options:
//
if (((f & std::ios_base::fixed) == std::ios_base::fixed) && (expon != -1))
digits += expon + 1;
if ((f & std::ios_base::scientific) == std::ios_base::scientific)
++digits;
//
// Extract the digits one at a time:
//
for (unsigned i = 0; i < digits; ++i)
{
eval_floor(digit, t);
eval_convert_to(&cdigit, digit);
result += static_cast<char>('0' + cdigit);
eval_subtract(t, digit);
eval_multiply(t, ten);
}
//
// Possibly round result:
//
if (digits >= 0)
{
eval_floor(digit, t);
eval_convert_to(&cdigit, digit);
eval_subtract(t, digit);
if ((cdigit == 5) && (t.compare(ui_type(0)) == 0))
{
// Bankers rounding:
if ((*result.rbegin() - '0') & 1)
{
round_string_up_at(result, static_cast<std::ptrdiff_t>(result.size() - 1u), expon);
}
}
else if (cdigit >= 5)
{
round_string_up_at(result, static_cast<std::ptrdiff_t>(result.size() - 1u), expon);
}
}
eval_floor(t, b);
if ((t.compare(b) == 0) && (static_cast<std::size_t>(expon + 1) < result.size()))
{
// Input is an integer, sometimes we get a result which is not an integer here as a result of printing too
// many digits, so lets round if required:
round_string_up_at(result, expon + 1, expon);
result.erase(static_cast<std::string::size_type>(expon + 1));
}
}
while ((static_cast<std::streamsize>(result.size()) > digits) && (result.size() != 0U))
{
// We may get here as a result of rounding...
if (result.size() > 1)
result.erase(result.size() - 1);
else
{
if (expon > 0)
--expon; // so we put less padding in the result.
else
++expon;
++digits;
}
}
BOOST_MP_ASSERT(org_digits >= 0);
if (isneg)
result.insert(static_cast<std::string::size_type>(0), 1, '-');
format_float_string(result, expon, org_digits, f, iszero);
return result;
}
template <class Backend>
void convert_from_string(Backend& b, const char* p)
{
using default_ops::eval_add;
using default_ops::eval_divide;
using default_ops::eval_multiply;
using default_ops::eval_pow;
using ui_type = typename std::tuple_element<0, typename Backend::unsigned_types>::type;
b = ui_type(0);
if (!p || (*p == 0))
return;
bool is_neg = false;
bool is_neg_expon = false;
constexpr ui_type ten = ui_type(10);
typename Backend::exponent_type expon = 0;
int digits_seen = 0;
using limits = std::numeric_limits<number<Backend, et_off>>;
constexpr int max_digits = limits::is_specialized ? limits::max_digits10 + 1 : INT_MAX;
if (*p == '+')
++p;
else if (*p == '-')
{
is_neg = true;
++p;
}
if ((std::strcmp(p, "nan") == 0) || (std::strcmp(p, "NaN") == 0) || (std::strcmp(p, "NAN") == 0))
{
eval_divide(b, ui_type(0));
if (is_neg)
b.negate();
return;
}
if ((std::strcmp(p, "inf") == 0) || (std::strcmp(p, "Inf") == 0) || (std::strcmp(p, "INF") == 0))
{
b = ui_type(1);
eval_divide(b, ui_type(0));
if (is_neg)
b.negate();
return;
}
//
// Grab all the leading digits before the decimal point:
//
while (std::isdigit(*p))
{
eval_multiply(b, ten);
eval_add(b, ui_type(*p - '0'));
++p;
++digits_seen;
}
if (*p == '.')
{
//
// Grab everything after the point, stop when we've seen
// enough digits, even if there are actually more available:
//
++p;
while (std::isdigit(*p))
{
eval_multiply(b, ten);
eval_add(b, ui_type(*p - '0'));
++p;
--expon;
if (++digits_seen > max_digits)
break;
}
while (std::isdigit(*p))
++p;
}
//
// Parse the exponent:
//
if ((*p == 'e') || (*p == 'E'))
{
++p;
if (*p == '+')
++p;
else if (*p == '-')
{
is_neg_expon = true;
++p;
}
typename Backend::exponent_type e2 = 0;
while (std::isdigit(*p))
{
e2 *= 10;
e2 += (*p - '0');
++p;
}
if (is_neg_expon)
e2 = -e2;
expon += e2;
}
if (expon)
{
// Scale by 10^expon, note that 10^expon can be
// outside the range of our number type, even though the
// result is within range, if that looks likely, then split
// the calculation in two:
Backend t;
t = ten;
if (expon > limits::min_exponent10 + 2)
{
eval_pow(t, t, expon);
eval_multiply(b, t);
}
else
{
eval_pow(t, t, expon + digits_seen + 1);
eval_multiply(b, t);
t = ten;
eval_pow(t, t, -digits_seen - 1);
eval_multiply(b, t);
}
}
if (is_neg)
b.negate();
if (*p)
{
// Unexpected input in string:
BOOST_MP_THROW_EXCEPTION(std::runtime_error("Unexpected characters in string being interpreted as a float128."));
}
}
}}} // namespace boost::multiprecision::detail
#endif
+101
View File
@@ -0,0 +1,101 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2022 Matt Borland. 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_MP_DETAIL_FPCLASSIFY_HPP
#define BOOST_MP_DETAIL_FPCLASSIFY_HPP
#include <cmath>
#include <limits>
#include <type_traits>
#include <boost/multiprecision/detail/standalone_config.hpp>
#include <boost/multiprecision/detail/float128_functions.hpp>
#ifdef BOOST_MP_MATH_AVAILABLE
#include <boost/math/special_functions/fpclassify.hpp>
#define BOOST_MP_ISNAN(x) (boost::math::isnan)(x)
#define BOOST_MP_ISINF(x) (boost::math::isinf)(x)
#define BOOST_MP_FPCLASSIFY(x) (boost::math::fpclassify)(x)
#define BOOST_MP_ISFINITE(x) (!(boost::math::isnan)(x) && !(boost::math::isinf)(x))
#else
namespace boost { namespace multiprecision { namespace detail {
template <typename T, typename std::enable_if<std::is_floating_point<T>::value
#ifdef BOOST_HAS_FLOAT128
|| std::is_same<T, float128_type>::value
#endif
, bool>::type = true>
inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
{
BOOST_MP_FLOAT128_USING;
using std::isnan;
return static_cast<bool>((isnan)(x));
}
template <typename T, typename std::enable_if<!std::is_floating_point<T>::value
#ifdef BOOST_HAS_FLOAT128
&& !std::is_same<T, float128_type>::value
#endif
, bool>::type = true>
inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
{
return x != x;
}
template <typename T, typename std::enable_if<std::is_floating_point<T>::value
#ifdef BOOST_HAS_FLOAT128
|| std::is_same<T, float128_type>::value
#endif
, bool>::type = true>
inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
{
BOOST_MP_FLOAT128_USING;
using std::isinf;
return static_cast<bool>((isinf)(x));
}
template <typename T, typename std::enable_if<!std::is_floating_point<T>::value
#ifdef BOOST_HAS_FLOAT128
&& !std::is_same<T, float128_type>::value
#endif
, bool>::type = true>
inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
{
return x == std::numeric_limits<T>::infinity() || x == -std::numeric_limits<T>::infinity();
}
template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = true>
inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
{
using std::fpclassify;
return fpclassify(x);
}
template <typename T, typename std::enable_if<!std::is_floating_point<T>::value, bool>::type = true>
inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
{
BOOST_MP_FLOAT128_USING;
using std::isnan;
using std::isinf;
using std::abs;
return (isnan)(x) ? FP_NAN :
(isinf)(x) ? FP_INFINITE :
abs(x) == T(0) ? FP_ZERO :
abs(x) > 0 && abs(x) < (std::numeric_limits<T>::min)() ? FP_SUBNORMAL : FP_NORMAL;
}
}}} // Namespace boost::multiprecision::detail
#define BOOST_MP_ISNAN(x) (boost::multiprecision::detail::isnan)(x)
#define BOOST_MP_ISINF(x) (boost::multiprecision::detail::isinf)(x)
#define BOOST_MP_FPCLASSIFY(x) (boost::multiprecision::detail::fpclassify)(x)
#define BOOST_MP_ISFINITE(x) (!(boost::multiprecision::detail::isnan)(x) && !(boost::multiprecision::detail::isinf)(x))
#endif
#endif // BOOST_MP_DETAIL_FPCLASSIFY_HPP
+288
View File
@@ -0,0 +1,288 @@
// 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)
//
// This file has no include guards or namespaces - it's expanded inline inside default_ops.hpp
//
template <class T>
void calc_log2(T& num, unsigned digits)
{
using ui_type = typename boost::multiprecision::detail::canonical<std::uint32_t, T>::type;
using si_type = typename std::tuple_element<0, typename T::signed_types>::type ;
//
// String value with 1100 digits:
//
static const char* string_val = "0."
"6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875"
"4200148102057068573368552023575813055703267075163507596193072757082837143519030703862389167347112335"
"0115364497955239120475172681574932065155524734139525882950453007095326366642654104239157814952043740"
"4303855008019441706416715186447128399681717845469570262716310645461502572074024816377733896385506952"
"6066834113727387372292895649354702576265209885969320196505855476470330679365443254763274495125040606"
"9438147104689946506220167720424524529612687946546193165174681392672504103802546259656869144192871608"
"2938031727143677826548775664850856740776484514644399404614226031930967354025744460703080960850474866"
"3852313818167675143866747664789088143714198549423151997354880375165861275352916610007105355824987941"
"4729509293113897155998205654392871700072180857610252368892132449713893203784393530887748259701715591"
"0708823683627589842589185353024363421436706118923678919237231467232172053401649256872747782344535347"
"6481149418642386776774406069562657379600867076257199184734022651462837904883062033061144630073719489";
//
// Check if we can just construct from string:
//
if (digits < 3640) // 3640 binary digits ~ 1100 decimal digits
{
num = string_val;
return;
}
//
// We calculate log2 from using the formula:
//
// ln(2) = 3/4 SUM[n>=0] ((-1)^n * N!^2 / (2^n(2n+1)!))
//
// Numerator and denominator are calculated separately and then
// divided at the end, we also precalculate the terms up to n = 5
// since these fit in a 32-bit integer anyway.
//
// See Gourdon, X., and Sebah, P. The logarithmic constant: log 2, Jan. 2004.
// Also http://www.mpfr.org/algorithms.pdf.
//
num = static_cast<ui_type>(1180509120uL);
T denom, next_term, temp;
denom = static_cast<ui_type>(1277337600uL);
next_term = static_cast<ui_type>(120uL);
si_type sign = -1;
ui_type limit = digits / 3 + 1;
for (ui_type n = 6; n < limit; ++n)
{
temp = static_cast<ui_type>(2);
eval_multiply(temp, ui_type(2 * n));
eval_multiply(temp, ui_type(2 * n + 1));
eval_multiply(num, temp);
eval_multiply(denom, temp);
sign = -sign;
eval_multiply(next_term, n);
eval_multiply(temp, next_term, next_term);
if (sign < 0)
temp.negate();
eval_add(num, temp);
}
eval_multiply(denom, ui_type(4));
eval_multiply(num, ui_type(3));
INSTRUMENT_BACKEND(denom);
INSTRUMENT_BACKEND(num);
eval_divide(num, denom);
INSTRUMENT_BACKEND(num);
}
template <class T>
void calc_e(T& result, unsigned digits)
{
using ui_type = typename std::tuple_element<0, typename T::unsigned_types>::type;
//
// 1100 digits in string form:
//
const char* string_val = "2."
"7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274"
"2746639193200305992181741359662904357290033429526059563073813232862794349076323382988075319525101901"
"1573834187930702154089149934884167509244761460668082264800168477411853742345442437107539077744992069"
"5517027618386062613313845830007520449338265602976067371132007093287091274437470472306969772093101416"
"9283681902551510865746377211125238978442505695369677078544996996794686445490598793163688923009879312"
"7736178215424999229576351482208269895193668033182528869398496465105820939239829488793320362509443117"
"3012381970684161403970198376793206832823764648042953118023287825098194558153017567173613320698112509"
"9618188159304169035159888851934580727386673858942287922849989208680582574927961048419844436346324496"
"8487560233624827041978623209002160990235304369941849146314093431738143640546253152096183690888707016"
"7683964243781405927145635490613031072085103837505101157477041718986106873969655212671546889570350354"
"0212340784981933432106817012100562788023519303322474501585390473041995777709350366041699732972508869";
//
// Check if we can just construct from string:
//
if (digits < 3640) // 3640 binary digits ~ 1100 decimal digits
{
result = string_val;
return;
}
T lim;
lim = ui_type(1);
eval_ldexp(lim, lim, digits);
//
// Standard evaluation from the definition of e: http://functions.wolfram.com/Constants/E/02/
//
result = ui_type(2);
T denom;
denom = ui_type(1);
ui_type i = 2;
do
{
eval_multiply(denom, i);
eval_multiply(result, i);
eval_add(result, ui_type(1));
++i;
} while (denom.compare(lim) <= 0);
eval_divide(result, denom);
}
template <class T>
void calc_pi(T& result, unsigned digits)
{
using ui_type = typename std::tuple_element<0, typename T::unsigned_types>::type;
using real_type = typename std::tuple_element<0, typename T::float_types>::type ;
//
// 1100 digits in string form:
//
const char* string_val = "3."
"1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
"8214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196"
"4428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273"
"7245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094"
"3305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912"
"9833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132"
"0005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235"
"4201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859"
"5024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303"
"5982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989"
"3809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913152";
//
// Check if we can just construct from string:
//
if (digits < 3640) // 3640 binary digits ~ 1100 decimal digits
{
result = string_val;
return;
}
T a;
a = ui_type(1);
T b;
T A(a);
T B;
B = real_type(0.5f);
T D;
D = real_type(0.25f);
T lim;
lim = ui_type(1);
eval_ldexp(lim, lim, -static_cast<int>(digits));
//
// This algorithm is from:
// Schonhage, A., Grotefeld, A. F. W., and Vetter, E. Fast Algorithms: A Multitape Turing
// Machine Implementation. BI Wissenschaftverlag, 1994.
// Also described in MPFR's algorithm guide: http://www.mpfr.org/algorithms.pdf.
//
// Let:
// a[0] = A[0] = 1
// B[0] = 1/2
// D[0] = 1/4
// Then:
// S[k+1] = (A[k]+B[k]) / 4
// b[k] = sqrt(B[k])
// a[k+1] = a[k]^2
// B[k+1] = 2(A[k+1]-S[k+1])
// D[k+1] = D[k] - 2^k(A[k+1]-B[k+1])
// Stop when |A[k]-B[k]| <= 2^(k-p)
// and PI = B[k]/D[k]
unsigned k = 1;
do
{
eval_add(result, A, B);
eval_ldexp(result, result, -2);
eval_sqrt(b, B);
eval_add(a, b);
eval_ldexp(a, a, -1);
eval_multiply(A, a, a);
eval_subtract(B, A, result);
eval_ldexp(B, B, 1);
eval_subtract(result, A, B);
bool neg = eval_get_sign(result) < 0;
if (neg)
result.negate();
if (result.compare(lim) <= 0)
break;
if (neg)
result.negate();
eval_ldexp(result, result, static_cast<int>(k - 1u));
eval_subtract(D, result);
++k;
eval_ldexp(lim, lim, 1);
} while (true);
eval_divide(result, B, D);
}
template <class T>
const T& get_constant_ln2()
{
static BOOST_MP_THREAD_LOCAL T result;
static BOOST_MP_THREAD_LOCAL long digits = 0;
if ((digits != boost::multiprecision::detail::digits2<number<T> >::value()))
{
boost::multiprecision::detail::maybe_promote_precision(&result);
calc_log2(result, boost::multiprecision::detail::digits2<number<T, et_on> >::value());
digits = boost::multiprecision::detail::digits2<number<T> >::value();
}
return result;
}
template <class T>
const T& get_constant_e()
{
static BOOST_MP_THREAD_LOCAL T result;
static BOOST_MP_THREAD_LOCAL long digits = 0;
if ((digits != boost::multiprecision::detail::digits2<number<T> >::value()))
{
boost::multiprecision::detail::maybe_promote_precision(&result);
calc_e(result, boost::multiprecision::detail::digits2<number<T, et_on> >::value());
digits = boost::multiprecision::detail::digits2<number<T> >::value();
}
return result;
}
template <class T>
const T& get_constant_pi()
{
static BOOST_MP_THREAD_LOCAL T result;
static BOOST_MP_THREAD_LOCAL long digits = 0;
if ((digits != boost::multiprecision::detail::digits2<number<T> >::value()))
{
boost::multiprecision::detail::maybe_promote_precision(&result);
calc_pi(result, boost::multiprecision::detail::digits2<number<T, et_on> >::value());
digits = boost::multiprecision::detail::digits2<number<T> >::value();
}
return result;
}
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
template <class T>
const T& get_constant_one_over_epsilon()
{
static BOOST_MP_THREAD_LOCAL T result;
static BOOST_MP_THREAD_LOCAL long digits = 0;
if ((digits != boost::multiprecision::detail::digits2<number<T> >::value()))
{
using ui_type = typename std::tuple_element<0, typename T::unsigned_types>::type;
boost::multiprecision::detail::maybe_promote_precision(&result);
result = static_cast<ui_type>(1u);
BOOST_IF_CONSTEXPR(std::numeric_limits<number<T> >::is_specialized)
eval_divide(result, std::numeric_limits<number<T> >::epsilon().backend());
else
eval_ldexp(result, result, boost::multiprecision::detail::digits2<number<T> >::value() - 1);
digits = boost::multiprecision::detail::digits2<number<T> >::value();
}
return result;
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
+905
View File
@@ -0,0 +1,905 @@
// Copyright Christopher Kormanyos 2002 - 2013.
// Copyright 2011 - 2013 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)
// This work is based on an earlier work:
// "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations",
// in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469
//
// This file has no include guards or namespaces - it's expanded inline inside default_ops.hpp
//
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 6326) // comparison of two constants
#pragma warning(disable : 4127) // conditional expression is constant
#endif
#include <boost/multiprecision/detail/standalone_config.hpp>
#include <boost/multiprecision/detail/no_exceptions_support.hpp>
#include <boost/multiprecision/detail/assert.hpp>
namespace detail {
template <typename T, typename U>
inline void pow_imp(T& result, const T& t, const U& p, const std::integral_constant<bool, false>&)
{
// Compute the pure power of typename T t^p.
// Use the S-and-X binary method, as described in
// D. E. Knuth, "The Art of Computer Programming", Vol. 2,
// Section 4.6.3 . The resulting computational complexity
// is order log2[abs(p)].
using int_type = typename boost::multiprecision::detail::canonical<U, T>::type;
if (&result == &t)
{
T temp;
pow_imp(temp, t, p, std::integral_constant<bool, false>());
result = temp;
return;
}
// This will store the result.
if (U(p % U(2)) != U(0))
{
result = t;
}
else
result = int_type(1);
U p2(p);
// The variable x stores the binary powers of t.
T x(t);
while (U(p2 /= 2) != U(0))
{
// Square x for each binary power.
eval_multiply(x, x);
const bool has_binary_power = (U(p2 % U(2)) != U(0));
if (has_binary_power)
{
// Multiply the result with each binary power contained in the exponent.
eval_multiply(result, x);
}
}
}
template <typename T, typename U>
inline void pow_imp(T& result, const T& t, const U& p, const std::integral_constant<bool, true>&)
{
// Signed integer power, just take care of the sign then call the unsigned version:
using int_type = typename boost::multiprecision::detail::canonical<U, T>::type;
using ui_type = typename boost::multiprecision::detail::make_unsigned<U>::type ;
if (p < 0)
{
T temp;
temp = static_cast<int_type>(1);
T denom;
pow_imp(denom, t, static_cast<ui_type>(-p), std::integral_constant<bool, false>());
eval_divide(result, temp, denom);
return;
}
pow_imp(result, t, static_cast<ui_type>(p), std::integral_constant<bool, false>());
}
} // namespace detail
template <typename T, typename U>
inline typename std::enable_if<boost::multiprecision::detail::is_integral<U>::value>::type eval_pow(T& result, const T& t, const U& p)
{
detail::pow_imp(result, t, p, boost::multiprecision::detail::is_signed<U>());
}
template <class T>
void hyp0F0(T& H0F0, const T& x)
{
// Compute the series representation of Hypergeometric0F0 taken from
// http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric0F0/06/01/
// There are no checks on input range or parameter boundaries.
using ui_type = typename std::tuple_element<0, typename T::unsigned_types>::type;
BOOST_MP_ASSERT(&H0F0 != &x);
long tol = boost::multiprecision::detail::digits2<number<T, et_on> >::value();
T t;
T x_pow_n_div_n_fact(x);
eval_add(H0F0, x_pow_n_div_n_fact, ui_type(1));
T lim;
eval_ldexp(lim, H0F0, static_cast<int>(1L - tol));
if (eval_get_sign(lim) < 0)
lim.negate();
ui_type n;
const unsigned series_limit =
boost::multiprecision::detail::digits2<number<T, et_on> >::value() < 100
? 100
: boost::multiprecision::detail::digits2<number<T, et_on> >::value();
// Series expansion of hyperg_0f0(; ; x).
for (n = 2; n < series_limit; ++n)
{
eval_multiply(x_pow_n_div_n_fact, x);
eval_divide(x_pow_n_div_n_fact, n);
eval_add(H0F0, x_pow_n_div_n_fact);
bool neg = eval_get_sign(x_pow_n_div_n_fact) < 0;
if (neg)
x_pow_n_div_n_fact.negate();
if (lim.compare(x_pow_n_div_n_fact) > 0)
break;
if (neg)
x_pow_n_div_n_fact.negate();
}
if (n >= series_limit)
BOOST_MP_THROW_EXCEPTION(std::runtime_error("H0F0 failed to converge"));
}
template <class T>
void hyp1F0(T& H1F0, const T& a, const T& x)
{
// Compute the series representation of Hypergeometric1F0 taken from
// http://functions.wolfram.com/HypergeometricFunctions/Hypergeometric1F0/06/01/01/
// and also see the corresponding section for the power function (i.e. x^a).
// There are no checks on input range or parameter boundaries.
using si_type = typename boost::multiprecision::detail::canonical<int, T>::type;
BOOST_MP_ASSERT(&H1F0 != &x);
BOOST_MP_ASSERT(&H1F0 != &a);
T x_pow_n_div_n_fact(x);
T pochham_a(a);
T ap(a);
eval_multiply(H1F0, pochham_a, x_pow_n_div_n_fact);
eval_add(H1F0, si_type(1));
T lim;
eval_ldexp(lim, H1F0, 1 - boost::multiprecision::detail::digits2<number<T, et_on> >::value());
if (eval_get_sign(lim) < 0)
lim.negate();
si_type n;
T term, part;
const si_type series_limit =
boost::multiprecision::detail::digits2<number<T, et_on> >::value() < 100
? 100
: boost::multiprecision::detail::digits2<number<T, et_on> >::value();
// Series expansion of hyperg_1f0(a; ; x).
for (n = 2; n < series_limit; n++)
{
eval_multiply(x_pow_n_div_n_fact, x);
eval_divide(x_pow_n_div_n_fact, n);
eval_increment(ap);
eval_multiply(pochham_a, ap);
eval_multiply(term, pochham_a, x_pow_n_div_n_fact);
eval_add(H1F0, term);
if (eval_get_sign(term) < 0)
term.negate();
if (lim.compare(term) >= 0)
break;
}
if (n >= series_limit)
BOOST_MP_THROW_EXCEPTION(std::runtime_error("H1F0 failed to converge"));
}
template <class T>
void eval_exp(T& result, const T& x)
{
static_assert(number_category<T>::value == number_kind_floating_point, "The exp function is only valid for floating point types.");
if (&x == &result)
{
T temp;
eval_exp(temp, x);
result = temp;
return;
}
using ui_type = typename boost::multiprecision::detail::canonical<unsigned, T>::type;
using si_type = typename boost::multiprecision::detail::canonical<int, T>::type ;
using exp_type = typename T::exponent_type ;
using canonical_exp_type = typename boost::multiprecision::detail::canonical<exp_type, T>::type;
// Handle special arguments.
int type = eval_fpclassify(x);
bool isneg = eval_get_sign(x) < 0;
if (type == static_cast<int>(FP_NAN))
{
result = x;
errno = EDOM;
return;
}
else if (type == static_cast<int>(FP_INFINITE))
{
if (isneg)
result = ui_type(0u);
else
result = x;
return;
}
else if (type == static_cast<int>(FP_ZERO))
{
result = ui_type(1);
return;
}
// Get local copy of argument and force it to be positive.
T xx = x;
T exp_series;
if (isneg)
xx.negate();
// Check the range of the argument.
if (xx.compare(si_type(1)) <= 0)
{
//
// Use series for exp(x) - 1:
//
T lim;
BOOST_IF_CONSTEXPR(std::numeric_limits<number<T, et_on> >::is_specialized)
lim = std::numeric_limits<number<T, et_on> >::epsilon().backend();
else
{
result = ui_type(1);
eval_ldexp(lim, result, 1 - boost::multiprecision::detail::digits2<number<T, et_on> >::value());
}
unsigned k = 2;
exp_series = xx;
result = si_type(1);
if (isneg)
eval_subtract(result, exp_series);
else
eval_add(result, exp_series);
eval_multiply(exp_series, xx);
eval_divide(exp_series, ui_type(k));
eval_add(result, exp_series);
while (exp_series.compare(lim) > 0)
{
++k;
eval_multiply(exp_series, xx);
eval_divide(exp_series, ui_type(k));
if (isneg && (k & 1))
eval_subtract(result, exp_series);
else
eval_add(result, exp_series);
}
return;
}
// Check for pure-integer arguments which can be either signed or unsigned.
typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type ll;
eval_trunc(exp_series, x);
eval_convert_to(&ll, exp_series);
if (x.compare(ll) == 0)
{
detail::pow_imp(result, get_constant_e<T>(), ll, std::integral_constant<bool, true>());
return;
}
else if (exp_series.compare(x) == 0)
{
// We have a value that has no fractional part, but is too large to fit
// in a long long, in this situation the code below will fail, so
// we're just going to assume that this will overflow:
if (isneg)
result = ui_type(0);
else
result = std::numeric_limits<number<T> >::has_infinity ? std::numeric_limits<number<T> >::infinity().backend() : (std::numeric_limits<number<T> >::max)().backend();
return;
}
// The algorithm for exp has been taken from MPFUN.
// exp(t) = [ (1 + r + r^2/2! + r^3/3! + r^4/4! ...)^p2 ] * 2^n
// where p2 is a power of 2 such as 2048, r = t_prime / p2, and
// t_prime = t - n*ln2, with n chosen to minimize the absolute
// value of t_prime. In the resulting Taylor series, which is
// implemented as a hypergeometric function, |r| is bounded by
// ln2 / p2. For small arguments, no scaling is done.
// Compute the exponential series of the (possibly) scaled argument.
eval_divide(result, xx, get_constant_ln2<T>());
exp_type n;
eval_convert_to(&n, result);
if (n == (std::numeric_limits<exp_type>::max)())
{
// Exponent is too large to fit in our exponent type:
if (isneg)
result = ui_type(0);
else
result = std::numeric_limits<number<T> >::has_infinity ? std::numeric_limits<number<T> >::infinity().backend() : (std::numeric_limits<number<T> >::max)().backend();
return;
}
// The scaling is 2^11 = 2048.
const si_type p2 = static_cast<si_type>(si_type(1) << 11);
eval_multiply(exp_series, get_constant_ln2<T>(), static_cast<canonical_exp_type>(n));
eval_subtract(exp_series, xx);
eval_divide(exp_series, p2);
exp_series.negate();
hyp0F0(result, exp_series);
detail::pow_imp(exp_series, result, p2, std::integral_constant<bool, true>());
result = ui_type(1);
eval_ldexp(result, result, n);
eval_multiply(exp_series, result);
if (isneg)
eval_divide(result, ui_type(1), exp_series);
else
result = exp_series;
}
template <class T>
void eval_log(T& result, const T& arg)
{
static_assert(number_category<T>::value == number_kind_floating_point, "The log function is only valid for floating point types.");
//
// We use a variation of http://dlmf.nist.gov/4.45#i
// using frexp to reduce the argument to x * 2^n,
// then let y = x - 1 and compute:
// log(x) = log(2) * n + log1p(1 + y)
//
using ui_type = typename boost::multiprecision::detail::canonical<unsigned, T>::type;
using exp_type = typename T::exponent_type ;
using canonical_exp_type = typename boost::multiprecision::detail::canonical<exp_type, T>::type;
using fp_type = typename std::tuple_element<0, typename T::float_types>::type ;
int s = eval_signbit(arg);
switch (eval_fpclassify(arg))
{
case FP_NAN:
result = arg;
errno = EDOM;
return;
case FP_INFINITE:
if (s)
break;
result = arg;
return;
case FP_ZERO:
result = std::numeric_limits<number<T> >::has_infinity ? std::numeric_limits<number<T> >::infinity().backend() : (std::numeric_limits<number<T> >::max)().backend();
result.negate();
errno = ERANGE;
return;
}
if (s)
{
result = std::numeric_limits<number<T> >::quiet_NaN().backend();
errno = EDOM;
return;
}
exp_type e;
T t;
eval_frexp(t, arg, &e);
bool alternate = false;
if (t.compare(fp_type(2) / fp_type(3)) <= 0)
{
alternate = true;
eval_ldexp(t, t, 1);
--e;
}
eval_multiply(result, get_constant_ln2<T>(), canonical_exp_type(e));
INSTRUMENT_BACKEND(result);
eval_subtract(t, ui_type(1)); /* -0.3 <= t <= 0.3 */
if (!alternate)
t.negate(); /* 0 <= t <= 0.33333 */
T pow = t;
T lim;
T t2;
if (alternate)
eval_add(result, t);
else
eval_subtract(result, t);
BOOST_IF_CONSTEXPR(std::numeric_limits<number<T, et_on> >::is_specialized)
eval_multiply(lim, result, std::numeric_limits<number<T, et_on> >::epsilon().backend());
else
eval_ldexp(lim, result, 1 - boost::multiprecision::detail::digits2<number<T, et_on> >::value());
if (eval_get_sign(lim) < 0)
lim.negate();
INSTRUMENT_BACKEND(lim);
ui_type k = 1;
do
{
++k;
eval_multiply(pow, t);
eval_divide(t2, pow, k);
INSTRUMENT_BACKEND(t2);
if (alternate && ((k & 1) != 0))
eval_add(result, t2);
else
eval_subtract(result, t2);
INSTRUMENT_BACKEND(result);
} while (lim.compare(t2) < 0);
}
template <class T>
const T& get_constant_log10()
{
static BOOST_MP_THREAD_LOCAL T result;
static BOOST_MP_THREAD_LOCAL long digits = 0;
if ((digits != boost::multiprecision::detail::digits2<number<T> >::value()))
{
using ui_type = typename boost::multiprecision::detail::canonical<unsigned, T>::type;
T ten;
ten = ui_type(10u);
eval_log(result, ten);
digits = boost::multiprecision::detail::digits2<number<T> >::value();
}
return result;
}
template <class T>
void eval_log10(T& result, const T& arg)
{
static_assert(number_category<T>::value == number_kind_floating_point, "The log10 function is only valid for floating point types.");
eval_log(result, arg);
eval_divide(result, get_constant_log10<T>());
}
template <class R, class T>
inline void eval_log2(R& result, const T& a)
{
eval_log(result, a);
eval_divide(result, get_constant_ln2<R>());
}
template <typename T>
inline void eval_pow(T& result, const T& x, const T& a)
{
static_assert(number_category<T>::value == number_kind_floating_point, "The pow function is only valid for floating point types.");
using si_type = typename boost::multiprecision::detail::canonical<int, T>::type;
using fp_type = typename std::tuple_element<0, typename T::float_types>::type ;
if ((&result == &x) || (&result == &a))
{
T t;
eval_pow(t, x, a);
result = t;
return;
}
if ((a.compare(si_type(1)) == 0) || (x.compare(si_type(1)) == 0))
{
result = x;
return;
}
if (a.compare(si_type(0)) == 0)
{
result = si_type(1);
return;
}
int type = eval_fpclassify(x);
switch (type)
{
case FP_ZERO:
switch (eval_fpclassify(a))
{
case FP_ZERO:
result = si_type(1);
break;
case FP_NAN:
result = a;
break;
case FP_NORMAL: {
// Need to check for a an odd integer as a special case:
BOOST_MP_TRY
{
typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type i;
eval_convert_to(&i, a);
if (a.compare(i) == 0)
{
if (eval_signbit(a))
{
if (i & 1)
{
result = std::numeric_limits<number<T> >::infinity().backend();
if (eval_signbit(x))
result.negate();
errno = ERANGE;
}
else
{
result = std::numeric_limits<number<T> >::infinity().backend();
errno = ERANGE;
}
}
else if (i & 1)
{
result = x;
}
else
result = si_type(0);
return;
}
}
BOOST_MP_CATCH(const std::exception&)
{
// fallthrough..
}
BOOST_MP_CATCH_END
BOOST_FALLTHROUGH;
}
default:
if (eval_signbit(a))
{
result = std::numeric_limits<number<T> >::infinity().backend();
errno = ERANGE;
}
else
result = x;
break;
}
return;
case FP_NAN:
result = x;
errno = ERANGE;
return;
default:;
}
int s = eval_get_sign(a);
if (s == 0)
{
result = si_type(1);
return;
}
if (s < 0)
{
T t, da;
t = a;
t.negate();
eval_pow(da, x, t);
eval_divide(result, si_type(1), da);
return;
}
typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type an;
typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type max_an =
std::numeric_limits<typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type>::is_specialized ? (std::numeric_limits<typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type>::max)() : static_cast<typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type>(1) << (sizeof(typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type) * CHAR_BIT - 2);
typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type min_an =
std::numeric_limits<typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type>::is_specialized ? (std::numeric_limits<typename boost::multiprecision::detail::canonical<std::intmax_t, T>::type>::min)() : -min_an;
T fa;
BOOST_MP_TRY
{
eval_convert_to(&an, a);
if (a.compare(an) == 0)
{
detail::pow_imp(result, x, an, std::integral_constant<bool, true>());
return;
}
}
BOOST_MP_CATCH(const std::exception&)
{
// conversion failed, just fall through, value is not an integer.
an = (std::numeric_limits<std::intmax_t>::max)();
}
BOOST_MP_CATCH_END
if ((eval_get_sign(x) < 0))
{
typename boost::multiprecision::detail::canonical<std::uintmax_t, T>::type aun;
BOOST_MP_TRY
{
eval_convert_to(&aun, a);
if (a.compare(aun) == 0)
{
fa = x;
fa.negate();
eval_pow(result, fa, a);
if (aun & 1u)
result.negate();
return;
}
}
BOOST_MP_CATCH(const std::exception&)
{
// conversion failed, just fall through, value is not an integer.
}
BOOST_MP_CATCH_END
eval_floor(result, a);
// -1^INF is a special case in C99:
if ((x.compare(si_type(-1)) == 0) && (eval_fpclassify(a) == FP_INFINITE))
{
result = si_type(1);
}
else if (a.compare(result) == 0)
{
// exponent is so large we have no fractional part:
if (x.compare(si_type(-1)) < 0)
{
result = std::numeric_limits<number<T, et_on> >::infinity().backend();
}
else
{
result = si_type(0);
}
}
else if (type == FP_INFINITE)
{
result = std::numeric_limits<number<T, et_on> >::infinity().backend();
}
else BOOST_IF_CONSTEXPR (std::numeric_limits<number<T, et_on> >::has_quiet_NaN)
{
result = std::numeric_limits<number<T, et_on> >::quiet_NaN().backend();
errno = EDOM;
}
else
{
BOOST_MP_THROW_EXCEPTION(std::domain_error("Result of pow is undefined or non-real and there is no NaN for this number type."));
}
return;
}
T t, da;
eval_subtract(da, a, an);
if ((x.compare(fp_type(0.5)) >= 0) && (x.compare(fp_type(0.9)) < 0) && (an < max_an) && (an > min_an))
{
if (a.compare(fp_type(1e-5f)) <= 0)
{
// Series expansion for small a.
eval_log(t, x);
eval_multiply(t, a);
hyp0F0(result, t);
return;
}
else
{
// Series expansion for moderately sized x. Note that for large power of a,
// the power of the integer part of a is calculated using the pown function.
if (an)
{
da.negate();
t = si_type(1);
eval_subtract(t, x);
hyp1F0(result, da, t);
detail::pow_imp(t, x, an, std::integral_constant<bool, true>());
eval_multiply(result, t);
}
else
{
da = a;
da.negate();
t = si_type(1);
eval_subtract(t, x);
hyp1F0(result, da, t);
}
}
}
else
{
// Series expansion for pow(x, a). Note that for large power of a, the power
// of the integer part of a is calculated using the pown function.
if (an)
{
eval_log(t, x);
eval_multiply(t, da);
eval_exp(result, t);
detail::pow_imp(t, x, an, std::integral_constant<bool, true>());
eval_multiply(result, t);
}
else
{
eval_log(t, x);
eval_multiply(t, a);
eval_exp(result, t);
}
}
}
template <class T, class A>
#if BOOST_WORKAROUND(BOOST_MSVC, < 1800)
inline typename std::enable_if<!boost::multiprecision::detail::is_integral<A>::value, void>::type
#else
inline typename std::enable_if<is_compatible_arithmetic_type<A, number<T> >::value && !boost::multiprecision::detail::is_integral<A>::value, void>::type
#endif
eval_pow(T& result, const T& x, const A& a)
{
// Note this one is restricted to float arguments since pow.hpp already has a version for
// integer powers....
using canonical_type = typename boost::multiprecision::detail::canonical<A, T>::type ;
using cast_type = typename std::conditional<std::is_same<A, canonical_type>::value, T, canonical_type>::type;
cast_type c;
c = a;
eval_pow(result, x, c);
}
template <class T, class A>
#if BOOST_WORKAROUND(BOOST_MSVC, < 1800)
inline void
#else
inline typename std::enable_if<is_compatible_arithmetic_type<A, number<T> >::value, void>::type
#endif
eval_pow(T& result, const A& x, const T& a)
{
using canonical_type = typename boost::multiprecision::detail::canonical<A, T>::type ;
using cast_type = typename std::conditional<std::is_same<A, canonical_type>::value, T, canonical_type>::type;
cast_type c;
c = x;
eval_pow(result, c, a);
}
template <class T>
void eval_exp2(T& result, const T& arg)
{
static_assert(number_category<T>::value == number_kind_floating_point, "The log function is only valid for floating point types.");
// Check for pure-integer arguments which can be either signed or unsigned.
typename boost::multiprecision::detail::canonical<typename T::exponent_type, T>::type i;
T temp;
BOOST_MP_TRY
{
eval_trunc(temp, arg);
eval_convert_to(&i, temp);
if (arg.compare(i) == 0)
{
temp = static_cast<typename std::tuple_element<0, typename T::unsigned_types>::type>(1u);
eval_ldexp(result, temp, i);
return;
}
}
#ifdef BOOST_MP_MATH_AVAILABLE
BOOST_MP_CATCH(const boost::math::rounding_error&)
{ /* Fallthrough */
}
#endif
BOOST_MP_CATCH(const std::runtime_error&)
{ /* Fallthrough */
}
BOOST_MP_CATCH_END
temp = static_cast<typename std::tuple_element<0, typename T::unsigned_types>::type>(2u);
eval_pow(result, temp, arg);
}
namespace detail {
template <class T>
void small_sinh_series(T x, T& result)
{
using ui_type = typename boost::multiprecision::detail::canonical<unsigned, T>::type;
bool neg = eval_get_sign(x) < 0;
if (neg)
x.negate();
T p(x);
T mult(x);
eval_multiply(mult, x);
result = x;
ui_type k = 1;
T lim(x);
eval_ldexp(lim, lim, 1 - boost::multiprecision::detail::digits2<number<T, et_on> >::value());
do
{
eval_multiply(p, mult);
eval_divide(p, ++k);
eval_divide(p, ++k);
eval_add(result, p);
} while (p.compare(lim) >= 0);
if (neg)
result.negate();
}
template <class T>
void sinhcosh(const T& x, T* p_sinh, T* p_cosh)
{
using ui_type = typename boost::multiprecision::detail::canonical<unsigned, T>::type;
using fp_type = typename std::tuple_element<0, typename T::float_types>::type ;
switch (eval_fpclassify(x))
{
case FP_NAN:
errno = EDOM;
// fallthrough...
case FP_INFINITE:
if (p_sinh)
*p_sinh = x;
if (p_cosh)
{
*p_cosh = x;
if (eval_get_sign(x) < 0)
p_cosh->negate();
}
return;
case FP_ZERO:
if (p_sinh)
*p_sinh = x;
if (p_cosh)
*p_cosh = ui_type(1);
return;
default:;
}
bool small_sinh = eval_get_sign(x) < 0 ? x.compare(fp_type(-0.5)) > 0 : x.compare(fp_type(0.5)) < 0;
if (p_cosh || !small_sinh)
{
T e_px, e_mx;
eval_exp(e_px, x);
eval_divide(e_mx, ui_type(1), e_px);
if (eval_signbit(e_mx) != eval_signbit(e_px))
e_mx.negate(); // Handles lack of signed zero in some types
if (p_sinh)
{
if (small_sinh)
{
small_sinh_series(x, *p_sinh);
}
else
{
eval_subtract(*p_sinh, e_px, e_mx);
eval_ldexp(*p_sinh, *p_sinh, -1);
}
}
if (p_cosh)
{
eval_add(*p_cosh, e_px, e_mx);
eval_ldexp(*p_cosh, *p_cosh, -1);
}
}
else
{
small_sinh_series(x, *p_sinh);
}
}
} // namespace detail
template <class T>
inline void eval_sinh(T& result, const T& x)
{
static_assert(number_category<T>::value == number_kind_floating_point, "The sinh function is only valid for floating point types.");
detail::sinhcosh(x, &result, static_cast<T*>(0));
}
template <class T>
inline void eval_cosh(T& result, const T& x)
{
static_assert(number_category<T>::value == number_kind_floating_point, "The cosh function is only valid for floating point types.");
detail::sinhcosh(x, static_cast<T*>(0), &result);
}
template <class T>
inline void eval_tanh(T& result, const T& x)
{
static_assert(number_category<T>::value == number_kind_floating_point, "The tanh function is only valid for floating point types.");
T c;
detail::sinhcosh(x, &result, &c);
if ((eval_fpclassify(result) == FP_INFINITE) && (eval_fpclassify(c) == FP_INFINITE))
{
bool s = eval_signbit(result) != eval_signbit(c);
result = static_cast<typename std::tuple_element<0, typename T::unsigned_types>::type>(1u);
if (s)
result.negate();
return;
}
eval_divide(result, c);
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
File diff suppressed because it is too large Load Diff
+78
View File
@@ -0,0 +1,78 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2022 Matt Borland. 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_MP_DETAIL_FUNCTIONS_TRUNC_HPP
#define BOOST_MP_DETAIL_FUNCTIONS_TRUNC_HPP
#include <cmath>
#include <limits>
#include <stdexcept>
#include <boost/multiprecision/detail/standalone_config.hpp>
#include <boost/multiprecision/detail/no_exceptions_support.hpp>
#ifdef BOOST_MP_MATH_AVAILABLE
#include <boost/math/special_functions/trunc.hpp>
#endif
namespace boost { namespace multiprecision { namespace detail {
namespace impl {
template <typename T>
inline T trunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
{
using std::floor;
using std::ceil;
return (arg > 0) ? floor(arg) : ceil(arg);
}
} // namespace impl
#ifdef BOOST_MP_MATH_AVAILABLE
template <typename T>
inline long long lltrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
{
return boost::math::lltrunc(arg);
}
template <typename T>
inline int itrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
{
return boost::math::itrunc(arg);
}
#else
template <typename T>
inline long long lltrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
{
T t = boost::multiprecision::detail::impl::trunc(arg);
if (t > LLONG_MAX)
{
BOOST_MP_THROW_EXCEPTION(std::domain_error("arg cannot be converted into a long long"));
}
return static_cast<long long>(t);
}
template <typename T>
inline int itrunc BOOST_PREVENT_MACRO_SUBSTITUTION (const T arg)
{
T t = boost::multiprecision::detail::impl::trunc(arg);
if (t > static_cast<T>(INT_MAX))
{
BOOST_MP_THROW_EXCEPTION(std::domain_error("arg cannot be converted into an int"));
}
return static_cast<int>(t);
}
#endif
}}} // Namespaces
#endif // BOOST_MP_DETAIL_FUNCTIONS_TRUNC_HPP
+687
View File
@@ -0,0 +1,687 @@
///////////////////////////////////////////////////////////////////////////////
// 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_MP_GENERIC_INTERCONVERT_HPP
#define BOOST_MP_GENERIC_INTERCONVERT_HPP
#include <cmath>
#include <limits>
#include <boost/multiprecision/detail/standalone_config.hpp>
#include <boost/multiprecision/detail/default_ops.hpp>
#include <boost/multiprecision/detail/no_exceptions_support.hpp>
#include <boost/multiprecision/detail/assert.hpp>
#include <boost/multiprecision/detail/functions/trunc.hpp>
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4127 6326)
#endif
namespace boost { namespace multiprecision { namespace detail {
template <class To, class From>
inline To do_cast(const From& from)
{
return static_cast<To>(from);
}
template <class To, class B, ::boost::multiprecision::expression_template_option et>
inline To do_cast(const number<B, et>& from)
{
return from.template convert_to<To>();
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_floating_point>& /*to_type*/, const std::integral_constant<int, number_kind_integer>& /*from_type*/)
{
using default_ops::eval_add;
using default_ops::eval_bitwise_and;
using default_ops::eval_convert_to;
using default_ops::eval_get_sign;
using default_ops::eval_is_zero;
using default_ops::eval_ldexp;
using default_ops::eval_right_shift;
// smallest unsigned type handled natively by "From" is likely to be it's limb_type:
using l_limb_type = typename canonical<unsigned char, From>::type;
// get the corresponding type that we can assign to "To":
using to_type = typename canonical<l_limb_type, To>::type;
From t(from);
bool is_neg = eval_get_sign(t) < 0;
if (is_neg)
t.negate();
// Pick off the first limb:
l_limb_type limb;
l_limb_type mask = static_cast<l_limb_type>(~static_cast<l_limb_type>(0));
From fl;
eval_bitwise_and(fl, t, mask);
eval_convert_to(&limb, fl);
to = static_cast<to_type>(limb);
eval_right_shift(t, std::numeric_limits<l_limb_type>::digits);
//
// Then keep picking off more limbs until "t" is zero:
//
To l;
unsigned shift = std::numeric_limits<l_limb_type>::digits;
while (!eval_is_zero(t))
{
eval_bitwise_and(fl, t, mask);
eval_convert_to(&limb, fl);
l = static_cast<to_type>(limb);
eval_right_shift(t, std::numeric_limits<l_limb_type>::digits);
eval_ldexp(l, l, shift);
eval_add(to, l);
shift += std::numeric_limits<l_limb_type>::digits;
}
//
// Finish off by setting the sign:
//
if (is_neg)
to.negate();
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_integer>& /*to_type*/, const std::integral_constant<int, number_kind_integer>& /*from_type*/)
{
using default_ops::eval_bitwise_and;
using default_ops::eval_bitwise_or;
using default_ops::eval_convert_to;
using default_ops::eval_get_sign;
using default_ops::eval_is_zero;
using default_ops::eval_left_shift;
using default_ops::eval_right_shift;
// smallest unsigned type handled natively by "From" is likely to be it's limb_type:
using limb_type = typename canonical<unsigned char, From>::type;
// get the corresponding type that we can assign to "To":
using to_type = typename canonical<limb_type, To>::type;
From t(from);
bool is_neg = eval_get_sign(t) < 0;
if (is_neg)
t.negate();
// Pick off the first limb:
limb_type limb;
limb_type mask = static_cast<limb_type>(~static_cast<limb_type>(0));
From fl;
eval_bitwise_and(fl, t, mask);
eval_convert_to(&limb, fl);
to = static_cast<to_type>(limb);
eval_right_shift(t, std::numeric_limits<limb_type>::digits);
//
// Then keep picking off more limbs until "t" is zero:
//
To l;
unsigned shift = std::numeric_limits<limb_type>::digits;
while (!eval_is_zero(t))
{
eval_bitwise_and(fl, t, mask);
eval_convert_to(&limb, fl);
l = static_cast<to_type>(limb);
eval_right_shift(t, std::numeric_limits<limb_type>::digits);
eval_left_shift(l, shift);
eval_bitwise_or(to, l);
shift += std::numeric_limits<limb_type>::digits;
}
//
// Finish off by setting the sign:
//
if (is_neg)
to.negate();
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_floating_point>& /*to_type*/, const std::integral_constant<int, number_kind_floating_point>& /*from_type*/)
{
#ifdef BOOST_MSVC
#pragma warning(push)
//#pragma warning(disable : 4127)
#endif
//
// The code here only works when the radix of "From" is 2, we could try shifting by other
// radixes but it would complicate things.... use a string conversion when the radix is other
// than 2:
//
BOOST_IF_CONSTEXPR(std::numeric_limits<number<From> >::radix != 2)
{
to = from.str(0, std::ios_base::fmtflags()).c_str();
return;
}
else
{
using ui_type = typename canonical<unsigned char, To>::type;
using default_ops::eval_add;
using default_ops::eval_convert_to;
using default_ops::eval_fpclassify;
using default_ops::eval_get_sign;
using default_ops::eval_is_zero;
using default_ops::eval_subtract;
//
// First classify the input, then handle the special cases:
//
int c = eval_fpclassify(from);
if (c == static_cast<int>(FP_ZERO))
{
to = ui_type(0);
return;
}
else if (c == static_cast<int>(FP_NAN))
{
to = static_cast<const char*>("nan");
return;
}
else if (c == static_cast<int>(FP_INFINITE))
{
to = static_cast<const char*>("inf");
if (eval_get_sign(from) < 0)
to.negate();
return;
}
typename From::exponent_type e;
From f, term;
to = ui_type(0);
eval_frexp(f, from, &e);
constexpr int shift = std::numeric_limits<std::intmax_t>::digits - 1;
while (!eval_is_zero(f))
{
// extract int sized bits from f:
eval_ldexp(f, f, shift);
eval_floor(term, f);
e -= shift;
eval_ldexp(to, to, shift);
typename boost::multiprecision::detail::canonical<std::intmax_t, To>::type ll;
eval_convert_to(&ll, term);
eval_add(to, ll);
eval_subtract(f, term);
}
using to_exponent = typename To::exponent_type;
if (e > (std::numeric_limits<to_exponent>::max)())
{
to = static_cast<const char*>("inf");
if (eval_get_sign(from) < 0)
to.negate();
return;
}
if (e < (std::numeric_limits<to_exponent>::min)())
{
to = ui_type(0);
if (eval_get_sign(from) < 0)
to.negate();
return;
}
eval_ldexp(to, to, static_cast<to_exponent>(e));
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_rational>& /*to_type*/, const std::integral_constant<int, number_kind_rational>& /*from_type*/)
{
using to_component_type = typename component_type<number<To> >::type;
number<From> t(from);
to_component_type n(numerator(t)), d(denominator(t));
using default_ops::assign_components;
assign_components(to, n.backend(), d.backend());
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_rational>& /*to_type*/, const std::integral_constant<int, number_kind_integer>& /*from_type*/)
{
using to_component_type = typename component_type<number<To> >::type;
number<From> t(from);
to_component_type n(t), d(1);
using default_ops::assign_components;
assign_components(to, n.backend(), d.backend());
}
template <class LargeInteger>
inline typename std::enable_if<is_signed_number<LargeInteger>::value>::type make_positive(LargeInteger& val)
{
if (val.sign() < 0)
val = -val;
}
template <class LargeInteger>
inline typename std::enable_if<!is_signed_number<LargeInteger>::value>::type make_positive(LargeInteger&){}
template <class R, class LargeInteger>
R safe_convert_to_float(const LargeInteger& i)
{
if (!i)
return R(0);
BOOST_IF_CONSTEXPR(std::numeric_limits<R>::is_specialized && std::numeric_limits<R>::max_exponent)
{
using std::ldexp;
LargeInteger val(i);
make_positive(val);
std::size_t mb = msb(val);
if (mb >= std::numeric_limits<R>::max_exponent)
{
int scale_factor = static_cast<int>(mb) + 1 - std::numeric_limits<R>::max_exponent;
BOOST_MP_ASSERT(scale_factor >= 1);
val >>= scale_factor;
R result = val.template convert_to<R>();
BOOST_IF_CONSTEXPR(std::numeric_limits<R>::digits == 0 || std::numeric_limits<R>::digits >= std::numeric_limits<R>::max_exponent)
{
//
// Calculate and add on the remainder, only if there are more
// digits in the mantissa that the size of the exponent, in
// other words if we are dropping digits in the conversion
// otherwise:
//
LargeInteger remainder(i);
remainder &= (LargeInteger(1) << scale_factor) - 1;
result += ldexp(safe_convert_to_float<R>(remainder), -scale_factor);
}
return i.sign() < 0 ? static_cast<R>(-result) : result;
}
}
return i.template convert_to<R>();
}
template <class To, class Integer>
inline typename std::enable_if<!(is_number<To>::value || std::is_floating_point<To>::value)>::type
generic_convert_rational_to_float_imp(To& result, const Integer& n, const Integer& d, const std::integral_constant<bool, true>&)
{
//
// If we get here, then there's something about one type or the other
// that prevents an exactly rounded result from being calculated
// (or at least it's not clear how to implement such a thing).
//
using default_ops::eval_divide;
number<To> fn(safe_convert_to_float<number<To> >(n)), fd(safe_convert_to_float<number<To> >(d));
eval_divide(result, fn.backend(), fd.backend());
}
template <class To, class Integer>
inline typename std::enable_if<is_number<To>::value || std::is_floating_point<To>::value>::type
generic_convert_rational_to_float_imp(To& result, const Integer& n, const Integer& d, const std::integral_constant<bool, true>&)
{
//
// If we get here, then there's something about one type or the other
// that prevents an exactly rounded result from being calculated
// (or at least it's not clear how to implement such a thing).
//
To fd(safe_convert_to_float<To>(d));
result = safe_convert_to_float<To>(n);
result /= fd;
}
template <class To, class Integer>
typename std::enable_if<is_number<To>::value || std::is_floating_point<To>::value>::type
generic_convert_rational_to_float_imp(To& result, Integer& num, Integer& denom, const std::integral_constant<bool, false>&)
{
//
// If we get here, then the precision of type To is known, and the integer type is unbounded
// so we can use integer division plus manipulation of the remainder to get an exactly
// rounded result.
//
if (num == 0)
{
result = 0;
return;
}
bool s = false;
if (num < 0)
{
s = true;
num = -num;
}
std::ptrdiff_t denom_bits = msb(denom);
std::ptrdiff_t shift = std::numeric_limits<To>::digits + denom_bits - msb(num);
if (shift > 0)
num <<= shift;
else if (shift < 0)
denom <<= boost::multiprecision::detail::unsigned_abs(shift);
Integer q, r;
divide_qr(num, denom, q, r);
std::ptrdiff_t q_bits = msb(q);
if (q_bits == std::numeric_limits<To>::digits - 1)
{
//
// Round up if 2 * r > denom:
//
r <<= 1;
int c = r.compare(denom);
if (c > 0)
++q;
else if ((c == 0) && (q & 1u))
{
++q;
}
}
else
{
BOOST_MP_ASSERT(q_bits == std::numeric_limits<To>::digits);
//
// We basically already have the rounding info:
//
if (q & 1u)
{
if (r || (q & 2u))
++q;
}
}
using std::ldexp;
result = do_cast<To>(q);
result = ldexp(result, static_cast<int>(-shift));
if (s)
result = -result;
}
template <class To, class Integer>
inline typename std::enable_if<!(is_number<To>::value || std::is_floating_point<To>::value)>::type
generic_convert_rational_to_float_imp(To& result, Integer& num, Integer& denom, const std::integral_constant<bool, false>& tag)
{
number<To> t;
generic_convert_rational_to_float_imp(t, num, denom, tag);
result = t.backend();
}
template <class To, class From>
inline void generic_convert_rational_to_float(To& result, const From& f)
{
//
// Type From is always a Backend to number<>, or an
// instance of number<>, but we allow
// To to be either a Backend type, or a real number type,
// that way we can call this from generic conversions, and
// from specific conversions to built in types.
//
using actual_from_type = typename std::conditional<is_number<From>::value, From, number<From> >::type ;
using actual_to_type = typename std::conditional<is_number<To>::value || std::is_floating_point<To>::value, To, number<To> >::type ;
using integer_type = typename component_type<actual_from_type>::type ;
using dispatch_tag = std::integral_constant<bool, !std::numeric_limits<integer_type>::is_specialized || std::numeric_limits<integer_type>::is_bounded || !std::numeric_limits<actual_to_type>::is_specialized || !std::numeric_limits<actual_to_type>::is_bounded || (std::numeric_limits<actual_to_type>::radix != 2)>;
integer_type n(numerator(static_cast<actual_from_type>(f))), d(denominator(static_cast<actual_from_type>(f)));
generic_convert_rational_to_float_imp(result, n, d, dispatch_tag());
}
template <class To, class From>
inline void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_floating_point>& /*to_type*/, const std::integral_constant<int, number_kind_rational>& /*from_type*/)
{
generic_convert_rational_to_float(to, from);
}
template <class To, class From>
void generic_interconvert_float2rational(To& to, const From& from, const std::integral_constant<int, 2>& /*radix*/)
{
using std::ldexp;
using std::frexp;
using ui_type = typename std::tuple_element<0, typename To::unsigned_types>::type;
constexpr int shift = std::numeric_limits<long long>::digits;
typename From::exponent_type e;
typename component_type<number<To>>::type num, denom;
number<From> val(from);
val = frexp(val, &e);
while (val)
{
val = ldexp(val, shift);
e -= shift;
long long ll = boost::multiprecision::detail::lltrunc(val);
val -= ll;
num <<= shift;
num += ll;
}
denom = ui_type(1u);
if (e < 0)
denom <<= -e;
else if (e > 0)
num <<= e;
assign_components(to, num.backend(), denom.backend());
}
template <class To, class From, int Radix>
void generic_interconvert_float2rational(To& to, const From& from, const std::integral_constant<int, Radix>& /*radix*/)
{
using std::ilogb;
using std::scalbn;
using std::pow;
using std::abs;
//
// This is almost the same as the binary case above, but we have to use
// scalbn and ilogb rather than ldexp and frexp, we also only extract
// one Radix digit at a time which is terribly inefficient!
//
using ui_type = typename std::tuple_element<0, typename To::unsigned_types>::type;
typename From::exponent_type e;
typename component_type<number<To>>::type num, denom;
number<From> val(from);
if (!val)
{
to = ui_type(0u);
return;
}
e = ilogb(val);
val = scalbn(val, -e);
while (val)
{
long long ll = boost::multiprecision::detail::lltrunc(val);
val -= ll;
val = scalbn(val, 1);
num *= Radix;
num += ll;
--e;
}
++e;
denom = ui_type(Radix);
denom = pow(denom, abs(e));
if (e > 0)
{
num *= denom;
denom = 1;
}
assign_components(to, num.backend(), denom.backend());
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_rational>& /*to_type*/, const std::integral_constant<int, number_kind_floating_point>& /*from_type*/)
{
generic_interconvert_float2rational(to, from, std::integral_constant<int, std::numeric_limits<number<From> >::is_specialized ? std::numeric_limits<number<From> >::radix : 2>());
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_integer>& /*to_type*/, const std::integral_constant<int, number_kind_rational>& /*from_type*/)
{
number<From> t(from);
number<To> result(numerator(t) / denominator(t));
to = result.backend();
}
template <class To, class From>
void generic_interconvert_float2int(To& to, const From& from, const std::integral_constant<int, 2>& /*radix*/)
{
using std::frexp;
using std::ldexp;
using exponent_type = typename From::exponent_type;
constexpr exponent_type shift = std::numeric_limits<long long>::digits;
exponent_type e;
number<To> num(0u);
number<From> val(from);
val = frexp(val, &e);
bool neg = false;
if (val.sign() < 0)
{
val.backend().negate();
neg = true;
}
while (e > 0)
{
exponent_type s = (std::min)(e, shift);
val = ldexp(val, s);
e -= s;
long long ll = boost::multiprecision::detail::lltrunc(val);
val -= ll;
num <<= s;
num += ll;
}
to = num.backend();
if (neg)
to.negate();
}
template <class To, class From, int Radix>
void generic_interconvert_float2int(To& to, const From& from, const std::integral_constant<int, Radix>& /*radix*/)
{
using std::ilogb;
using std::scalbn;
//
// This is almost the same as the binary case above, but we have to use
// scalbn and ilogb rather than ldexp and frexp, we also only extract
// one Radix digit at a time which is terribly inefficient!
//
typename From::exponent_type e;
number<To> num(0u);
number<From> val(from);
e = ilogb(val);
val = scalbn(val, -e);
while (e >= 0)
{
long long ll = boost::multiprecision::detail::lltrunc(val);
val -= ll;
val = scalbn(val, 1);
num *= Radix;
num += ll;
--e;
}
to = num.backend();
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_integer>& /*to_type*/, const std::integral_constant<int, number_kind_floating_point>& /*from_type*/)
{
generic_interconvert_float2int(to, from, std::integral_constant<int, (std::numeric_limits<number<From> >::is_specialized ? std::numeric_limits<number<From> >::radix : 2)>());
}
template <class To, class From, class tag>
void generic_interconvert_complex_to_scalar(To& to, const From& from, const std::integral_constant<bool, true>&, const tag&)
{
// We just want the real part, and "to" is the correct type already:
eval_real(to, from);
To im;
eval_imag(im, from);
if (!eval_is_zero(im))
BOOST_MP_THROW_EXCEPTION(std::runtime_error("Could not convert imaginary number to scalar."));
}
template <class To, class From>
void generic_interconvert_complex_to_scalar(To& to, const From& from, const std::integral_constant<bool, false>&, const std::integral_constant<bool, true>&)
{
using component_number = typename component_type<number<From> >::type;
using component_backend = typename component_number::backend_type ;
//
// Get the real part and copy-construct the result from it:
//
scoped_precision_options<component_number> scope(from);
component_backend r;
generic_interconvert_complex_to_scalar(r, from, std::integral_constant<bool, true>(), std::integral_constant<bool, true>());
to = r;
}
template <class To, class From>
void generic_interconvert_complex_to_scalar(To& to, const From& from, const std::integral_constant<bool, false>&, const std::integral_constant<bool, false>&)
{
using component_number = typename component_type<number<From> >::type;
using component_backend = typename component_number::backend_type;
//
// Get the real part and use a generic_interconvert to type To:
//
scoped_precision_options<component_number> scope(from);
component_backend r;
generic_interconvert_complex_to_scalar(r, from, std::integral_constant<bool, true>(), std::integral_constant<bool, true>());
generic_interconvert(to, r, std::integral_constant<int, number_category<To>::value>(), std::integral_constant<int, number_category<component_backend>::value>());
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_floating_point>& /*to_type*/, const std::integral_constant<int, number_kind_complex>& /*from_type*/)
{
using component_number = typename component_type<number<From> >::type;
using component_backend = typename component_number::backend_type ;
generic_interconvert_complex_to_scalar(to, from, std::integral_constant<bool, std::is_same<component_backend, To>::value>(), std::integral_constant<bool, std::is_constructible<To, const component_backend&>::value>());
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_integer>& /*to_type*/, const std::integral_constant<int, number_kind_complex>& /*from_type*/)
{
using component_number = typename component_type<number<From> >::type;
using component_backend = typename component_number::backend_type ;
generic_interconvert_complex_to_scalar(to, from, std::integral_constant<bool, std::is_same<component_backend, To>::value>(), std::integral_constant<bool, std::is_constructible<To, const component_backend&>::value>());
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_rational>& /*to_type*/, const std::integral_constant<int, number_kind_complex>& /*from_type*/)
{
using component_number = typename component_type<number<From> >::type;
using component_backend = typename component_number::backend_type ;
generic_interconvert_complex_to_scalar(to, from, std::integral_constant<bool, std::is_same<component_backend, To>::value>(), std::integral_constant<bool, std::is_constructible<To, const component_backend&>::value>());
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_complex>& /*to_type*/, const std::integral_constant<int, number_kind_integer>& /*from_type*/)
{
using component_number = typename component_type<number<To> >::type;
scoped_source_precision<number<From> > scope1;
scoped_precision_options<component_number> scope2(number<To>::thread_default_precision(), number<To>::thread_default_variable_precision_options());
(void)scope1;
(void)scope2;
number<From> f(from);
component_number scalar(f);
number<To> result(scalar);
to = result.backend();
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_complex>& /*to_type*/, const std::integral_constant<int, number_kind_rational>& /*from_type*/)
{
using component_number = typename component_type<number<To> >::type;
scoped_source_precision<number<From> > scope1;
scoped_precision_options<component_number> scope2(number<To>::thread_default_precision(), number<To>::thread_default_variable_precision_options());
(void)scope1;
(void)scope2;
number<From> f(from);
component_number scalar(f);
number<To> result(scalar);
to = result.backend();
}
template <class To, class From>
void generic_interconvert(To& to, const From& from, const std::integral_constant<int, number_kind_complex>& /*to_type*/, const std::integral_constant<int, number_kind_floating_point>& /*from_type*/)
{
using component_number = typename component_type<number<To> >::type;
scoped_source_precision<number<From> > scope1;
scoped_precision_options<component_number> scope2(number<To>::thread_default_precision(), number<To>::thread_default_variable_precision_options());
(void)scope1;
(void)scope2;
number<From> f(from);
component_number scalar(f);
number<To> result(scalar);
to = result.backend();
}
template <class To, class From, int Tag1, int Tag2>
void generic_interconvert(To& /*to*/, const From& /*from*/, const std::integral_constant<int, Tag1>& /*to_type*/, const std::integral_constant<int, Tag2>& /*from_type*/)
{
static_assert(sizeof(To) == 0, "Sorry, you asked for a conversion bewteen types that hasn't been implemented yet!!");
}
}
}
} // namespace boost::multiprecision::detail
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif // BOOST_MP_GENERIC_INTERCONVERT_HPP
+56
View File
@@ -0,0 +1,56 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2021 Matt Borland. 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_MP_DETAIL_HASH_HPP
#define BOOST_MP_DETAIL_HASH_HPP
#include <cstddef>
#include <functional>
#include <boost/multiprecision/detail/standalone_config.hpp>
namespace boost { namespace multiprecision { namespace detail {
template <typename T>
inline std::size_t hash_value(const T& v)
{
std::hash<T> hasher;
return hasher(v);
}
#if defined(BOOST_HAS_INT128)
std::size_t hash_value(const uint128_type& val);
inline std::size_t hash_value(const int128_type& val)
{
return hash_value(static_cast<uint128_type>(val));
}
#endif
inline void hash_combine(std::size_t&) {}
template <typename T, typename... Args>
inline void hash_combine(std::size_t& seed, const T& v, Args... args)
{
constexpr std::size_t adder = 0x9e3779b9;
seed = seed ^ (hash_value(v) + adder + (seed<<6) + (seed>>2));
hash_combine(seed, args...);
}
#if defined(BOOST_HAS_INT128)
inline std::size_t hash_value(const uint128_type& val)
{
std::size_t result = static_cast<std::size_t>(val);
hash_combine(result, static_cast<std::size_t>(val >> 64));
return result;
}
#endif
}}} // Namespaces
#endif // BOOST_MP_DETAIL_HASH_HPP
+474
View File
@@ -0,0 +1,474 @@
///////////////////////////////////////////////////////////////
// Copyright 2012 John Maddock. 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_DETAIL_INTEGER_OPS_HPP
#define BOOST_MP_DETAIL_INTEGER_OPS_HPP
#include <boost/multiprecision/number.hpp>
#include <boost/multiprecision/detail/no_exceptions_support.hpp>
namespace boost { namespace multiprecision {
namespace default_ops {
template <class Backend>
inline BOOST_MP_CXX14_CONSTEXPR void eval_qr(const Backend& x, const Backend& y, Backend& q, Backend& r)
{
eval_divide(q, x, y);
eval_modulus(r, x, y);
}
template <class Backend, class Integer>
inline BOOST_MP_CXX14_CONSTEXPR Integer eval_integer_modulus(const Backend& x, Integer val)
{
BOOST_MP_USING_ABS
using default_ops::eval_convert_to;
using default_ops::eval_modulus;
using int_type = typename boost::multiprecision::detail::canonical<Integer, Backend>::type;
Backend t;
eval_modulus(t, x, static_cast<int_type>(val));
Integer result(0);
eval_convert_to(&result, t);
return abs(result);
}
template <class B>
inline BOOST_MP_CXX14_CONSTEXPR void eval_gcd(B& result, const B& a, const B& b)
{
using default_ops::eval_get_sign;
using default_ops::eval_is_zero;
using default_ops::eval_lsb;
std::ptrdiff_t shift(0);
B u(a), v(b);
int s = eval_get_sign(u);
/* GCD(0,x) := x */
if (s < 0)
{
u.negate();
}
else if (s == 0)
{
result = v;
return;
}
s = eval_get_sign(v);
if (s < 0)
{
v.negate();
}
else if (s == 0)
{
result = u;
return;
}
/* Let shift := lg K, where K is the greatest power of 2
dividing both u and v. */
std::size_t us = eval_lsb(u);
std::size_t vs = eval_lsb(v);
shift = static_cast<std::ptrdiff_t>((std::min)(us, vs));
eval_right_shift(u, us);
eval_right_shift(v, vs);
do
{
/* Now u and v are both odd, so diff(u, v) is even.
Let u = min(u, v), v = diff(u, v)/2. */
s = u.compare(v);
if (s > 0)
u.swap(v);
if (s == 0)
break;
eval_subtract(v, u);
vs = eval_lsb(v);
eval_right_shift(v, vs);
} while (true);
result = u;
eval_left_shift(result, shift);
}
template <class B>
inline BOOST_MP_CXX14_CONSTEXPR void eval_lcm(B& result, const B& a, const B& b)
{
using ui_type = typename std::tuple_element<0, typename B::unsigned_types>::type;
B t;
eval_gcd(t, a, b);
if (eval_is_zero(t))
{
result = static_cast<ui_type>(0);
}
else
{
eval_divide(result, a, t);
eval_multiply(result, b);
}
if (eval_get_sign(result) < 0)
result.negate();
}
} // namespace default_ops
template <class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer>::type
divide_qr(const number<Backend, ExpressionTemplates>& x, const number<Backend, ExpressionTemplates>& y,
number<Backend, ExpressionTemplates>& q, number<Backend, ExpressionTemplates>& r)
{
using default_ops::eval_qr;
eval_qr(x.backend(), y.backend(), q.backend(), r.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer>::type
divide_qr(const number<Backend, ExpressionTemplates>& x, const multiprecision::detail::expression<tag, A1, A2, A3, A4>& y,
number<Backend, ExpressionTemplates>& q, number<Backend, ExpressionTemplates>& r)
{
divide_qr(x, number<Backend, ExpressionTemplates>(y), q, r);
}
template <class tag, class A1, class A2, class A3, class A4, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer>::type
divide_qr(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& x, const number<Backend, ExpressionTemplates>& y,
number<Backend, ExpressionTemplates>& q, number<Backend, ExpressionTemplates>& r)
{
divide_qr(number<Backend, ExpressionTemplates>(x), y, q, r);
}
template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer>::type
divide_qr(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& x, const multiprecision::detail::expression<tagb, A1b, A2b, A3b, A4b>& y,
number<Backend, ExpressionTemplates>& q, number<Backend, ExpressionTemplates>& r)
{
divide_qr(number<Backend, ExpressionTemplates>(x), number<Backend, ExpressionTemplates>(y), q, r);
}
template <class Backend, expression_template_option ExpressionTemplates, class Integer>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_integral<Integer>::value && (number_category<Backend>::value == number_kind_integer), Integer>::type
integer_modulus(const number<Backend, ExpressionTemplates>& x, Integer val)
{
using default_ops::eval_integer_modulus;
return eval_integer_modulus(x.backend(), val);
}
template <class tag, class A1, class A2, class A3, class A4, class Integer>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_integral<Integer>::value && (number_category<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_integer), Integer>::type
integer_modulus(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& x, Integer val)
{
using result_type = typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type;
return integer_modulus(result_type(x), val);
}
template <class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer, std::size_t>::type
lsb(const number<Backend, ExpressionTemplates>& x)
{
using default_ops::eval_lsb;
return eval_lsb(x.backend());
}
template <class tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_integer, std::size_t>::type
lsb(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& x)
{
using number_type = typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type;
number_type n(x);
using default_ops::eval_lsb;
return eval_lsb(n.backend());
}
template <class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer, std::size_t>::type
msb(const number<Backend, ExpressionTemplates>& x)
{
using default_ops::eval_msb;
return eval_msb(x.backend());
}
template <class tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_integer, std::size_t>::type
msb(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& x)
{
using number_type = typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type;
number_type n(x);
using default_ops::eval_msb;
return eval_msb(n.backend());
}
template <class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer, bool>::type
bit_test(const number<Backend, ExpressionTemplates>& x, std::size_t index)
{
using default_ops::eval_bit_test;
return eval_bit_test(x.backend(), index);
}
template <class tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_integer, bool>::type
bit_test(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& x, std::size_t index)
{
using number_type = typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type;
number_type n(x);
using default_ops::eval_bit_test;
return eval_bit_test(n.backend(), index);
}
template <class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer, number<Backend, ExpressionTemplates>&>::type
bit_set(number<Backend, ExpressionTemplates>& x, std::size_t index)
{
using default_ops::eval_bit_set;
eval_bit_set(x.backend(), index);
return x;
}
template <class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer, number<Backend, ExpressionTemplates>&>::type
bit_unset(number<Backend, ExpressionTemplates>& x, std::size_t index)
{
using default_ops::eval_bit_unset;
eval_bit_unset(x.backend(), index);
return x;
}
template <class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<Backend>::value == number_kind_integer, number<Backend, ExpressionTemplates>&>::type
bit_flip(number<Backend, ExpressionTemplates>& x, std::size_t index)
{
using default_ops::eval_bit_flip;
eval_bit_flip(x.backend(), index);
return x;
}
namespace default_ops {
//
// Within powm, we need a type with twice as many digits as the argument type, define
// a traits class to obtain that type:
//
template <class Backend>
struct double_precision_type
{
using type = Backend;
};
//
// If the exponent is a signed integer type, then we need to
// check the value is positive:
//
template <class Backend>
inline BOOST_MP_CXX14_CONSTEXPR void check_sign_of_backend(const Backend& v, const std::integral_constant<bool, true>)
{
if (eval_get_sign(v) < 0)
{
BOOST_MP_THROW_EXCEPTION(std::runtime_error("powm requires a positive exponent."));
}
}
template <class Backend>
inline BOOST_MP_CXX14_CONSTEXPR void check_sign_of_backend(const Backend&, const std::integral_constant<bool, false>) {}
//
// Calculate (a^p)%c:
//
template <class Backend>
BOOST_MP_CXX14_CONSTEXPR void eval_powm(Backend& result, const Backend& a, const Backend& p, const Backend& c)
{
using default_ops::eval_bit_test;
using default_ops::eval_get_sign;
using default_ops::eval_modulus;
using default_ops::eval_multiply;
using default_ops::eval_right_shift;
using double_type = typename double_precision_type<Backend>::type ;
using ui_type = typename boost::multiprecision::detail::canonical<unsigned char, double_type>::type;
check_sign_of_backend(p, std::integral_constant<bool, std::numeric_limits<number<Backend> >::is_signed>());
double_type x, y(a), b(p), t;
x = ui_type(1u);
while (eval_get_sign(b) > 0)
{
if (eval_bit_test(b, 0))
{
eval_multiply(t, x, y);
eval_modulus(x, t, c);
}
eval_multiply(t, y, y);
eval_modulus(y, t, c);
eval_right_shift(b, ui_type(1));
}
Backend x2(x);
eval_modulus(result, x2, c);
}
template <class Backend, class Integer>
BOOST_MP_CXX14_CONSTEXPR void eval_powm(Backend& result, const Backend& a, const Backend& p, Integer c)
{
using double_type = typename double_precision_type<Backend>::type ;
using ui_type = typename boost::multiprecision::detail::canonical<unsigned char, double_type>::type;
using i1_type = typename boost::multiprecision::detail::canonical<Integer, double_type>::type ;
using i2_type = typename boost::multiprecision::detail::canonical<Integer, Backend>::type ;
using default_ops::eval_bit_test;
using default_ops::eval_get_sign;
using default_ops::eval_modulus;
using default_ops::eval_multiply;
using default_ops::eval_right_shift;
check_sign_of_backend(p, std::integral_constant<bool, std::numeric_limits<number<Backend> >::is_signed>());
if (eval_get_sign(p) < 0)
{
BOOST_MP_THROW_EXCEPTION(std::runtime_error("powm requires a positive exponent."));
}
double_type x, y(a), b(p), t;
x = ui_type(1u);
while (eval_get_sign(b) > 0)
{
if (eval_bit_test(b, 0))
{
eval_multiply(t, x, y);
eval_modulus(x, t, static_cast<i1_type>(c));
}
eval_multiply(t, y, y);
eval_modulus(y, t, static_cast<i1_type>(c));
eval_right_shift(b, ui_type(1));
}
Backend x2(x);
eval_modulus(result, x2, static_cast<i2_type>(c));
}
template <class Backend, class Integer>
BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_unsigned<Integer>::value >::type eval_powm(Backend& result, const Backend& a, Integer b, const Backend& c)
{
using double_type = typename double_precision_type<Backend>::type ;
using ui_type = typename boost::multiprecision::detail::canonical<unsigned char, double_type>::type;
using default_ops::eval_bit_test;
using default_ops::eval_get_sign;
using default_ops::eval_modulus;
using default_ops::eval_multiply;
using default_ops::eval_right_shift;
double_type x, y(a), t;
x = ui_type(1u);
while (b > 0)
{
if (b & 1)
{
eval_multiply(t, x, y);
eval_modulus(x, t, c);
}
eval_multiply(t, y, y);
eval_modulus(y, t, c);
b >>= 1;
}
Backend x2(x);
eval_modulus(result, x2, c);
}
template <class Backend, class Integer>
BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_signed<Integer>::value && boost::multiprecision::detail::is_integral<Integer>::value>::type eval_powm(Backend& result, const Backend& a, Integer b, const Backend& c)
{
if (b < 0)
{
BOOST_MP_THROW_EXCEPTION(std::runtime_error("powm requires a positive exponent."));
}
eval_powm(result, a, static_cast<typename boost::multiprecision::detail::make_unsigned<Integer>::type>(b), c);
}
template <class Backend, class Integer1, class Integer2>
BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_unsigned<Integer1>::value >::type eval_powm(Backend& result, const Backend& a, Integer1 b, Integer2 c)
{
using double_type = typename double_precision_type<Backend>::type ;
using ui_type = typename boost::multiprecision::detail::canonical<unsigned char, double_type>::type;
using i1_type = typename boost::multiprecision::detail::canonical<Integer1, double_type>::type ;
using i2_type = typename boost::multiprecision::detail::canonical<Integer2, Backend>::type ;
using default_ops::eval_bit_test;
using default_ops::eval_get_sign;
using default_ops::eval_modulus;
using default_ops::eval_multiply;
using default_ops::eval_right_shift;
double_type x, y(a), t;
x = ui_type(1u);
while (b > 0)
{
if (b & 1)
{
eval_multiply(t, x, y);
eval_modulus(x, t, static_cast<i1_type>(c));
}
eval_multiply(t, y, y);
eval_modulus(y, t, static_cast<i1_type>(c));
b >>= 1;
}
Backend x2(x);
eval_modulus(result, x2, static_cast<i2_type>(c));
}
template <class Backend, class Integer1, class Integer2>
BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_signed<Integer1>::value && boost::multiprecision::detail::is_integral<Integer1>::value>::type eval_powm(Backend& result, const Backend& a, Integer1 b, Integer2 c)
{
if (b < 0)
{
BOOST_MP_THROW_EXCEPTION(std::runtime_error("powm requires a positive exponent."));
}
eval_powm(result, a, static_cast<typename boost::multiprecision::detail::make_unsigned<Integer1>::type>(b), c);
}
struct powm_func
{
template <class T, class U, class V>
BOOST_MP_CXX14_CONSTEXPR void operator()(T& result, const T& b, const U& p, const V& m) const
{
eval_powm(result, b, p, m);
}
template <class R, class T, class U, class V>
BOOST_MP_CXX14_CONSTEXPR void operator()(R& result, const T& b, const U& p, const V& m) const
{
T temp;
eval_powm(temp, b, p, m);
result = std::move(temp);
}
};
} // namespace default_ops
template <class T, class U, class V>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<
(number_category<T>::value == number_kind_integer) &&
(is_number<T>::value || is_number_expression<T>::value) &&
(is_number<U>::value || is_number_expression<U>::value || boost::multiprecision::detail::is_integral<U>::value) &&
(is_number<V>::value || is_number_expression<V>::value || boost::multiprecision::detail::is_integral<V>::value),
typename std::conditional<
is_no_et_number<T>::value,
T,
typename std::conditional<
is_no_et_number<U>::value,
U,
typename std::conditional<
is_no_et_number<V>::value,
V,
detail::expression<detail::function, default_ops::powm_func, T, U, V> >::type>::type>::type>::type
powm(const T& b, const U& p, const V& mod)
{
return detail::expression<detail::function, default_ops::powm_func, T, U, V>(
default_ops::powm_func(), b, p, mod);
}
}} // namespace boost::multiprecision
#endif
+39
View File
@@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////
// Copyright 2019 John Maddock. 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
//
// We used to use lexical_cast internally for quick conversions from integers
// to strings, but that breaks if the global locale is something other than "C".
// See https://github.com/boostorg/multiprecision/issues/167.
//
#ifndef BOOST_MP_DETAIL_ITOS_HPP
#define BOOST_MP_DETAIL_ITOS_HPP
namespace boost { namespace multiprecision { namespace detail {
template <class Integer>
std::string itos(Integer val)
{
if (!val) return "0";
std::string result;
bool isneg = false;
if (val < 0)
{
val = -val;
isneg = true;
}
while (val)
{
result.insert(result.begin(), char('0' + (val % 10)));
val /= 10;
}
if (isneg)
result.insert(result.begin(), '-');
return result;
}
}}} // namespace boost::multiprecision::detail
#endif
+106
View File
@@ -0,0 +1,106 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2016 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_MP_MIN_MAX_HPP
#define BOOST_MP_MIN_MAX_HPP
#include <boost/multiprecision/traits/is_backend.hpp>
namespace boost { namespace multiprecision {
//
// Expression template overloads for (min) and (max):
//
// Introduced in response to https://svn.boost.org/trac/boost/ticket/11149
// note that these can not legally be injected into namespace std, and that doing so
// may break future enhancements to the standard. None the less adding
// namespace std{ using boost::multiprecision::(min); using boost::multiprecision::(max); }
// to your code may get some generic code working that wouldn't work otherwise.
//
// The use of enable_if on the return type is to avoid poisoning std::min/max,
// otherwise attempting to make an explicit call to min<long>(a, b) when these and std
// versions are in scope, will cause the compiler to try to instantiate the signatures
// for our versions as well as the std ones, which in turn instantiates number<long>
// which fails to compile as "long" is not a valid backend type.
//
template <class Backend>
inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on>&>::type(min)(const number<Backend, et_on>& a, const number<Backend, et_on>& b)
{
return a < b ? a : b;
}
template <class Backend, class tag, class A1, class A2, class A3, class A4>
inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on> >::type(min)(const number<Backend, et_on>& a, const detail::expression<tag, A1, A2, A3, A4>& b)
{
number<Backend, et_on> t(b);
if (a < t)
return a;
return std::move(t);
}
template <class tag, class A1, class A2, class A3, class A4, class Backend>
inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on> >::type(min)(const detail::expression<tag, A1, A2, A3, A4>& a, const number<Backend, et_on>& b)
{
number<Backend, et_on> t(a);
if (t < b)
return std::move(t);
return b;
}
template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
inline typename detail::expression<tag, A1, A2, A3, A4>::result_type(min)(const detail::expression<tag, A1, A2, A3, A4>& a, const detail::expression<tagb, A1b, A2b, A3b, A4b>& b)
{
typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
if (t1 < t2)
return std::move(t1);
return std::move(t2);
}
template <class tag, class A1, class A2, class A3, class A4>
inline typename detail::expression<tag, A1, A2, A3, A4>::result_type(min)(const detail::expression<tag, A1, A2, A3, A4>& a, const detail::expression<tag, A1, A2, A3, A4>& b)
{
typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
if (t1 < t2)
return std::move(t1);
return std::move(t2);
}
template <class Backend>
inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on>&>::type(max)(const number<Backend, et_on>& a, const number<Backend, et_on>& b)
{
return a > b ? a : b;
}
template <class Backend, class tag, class A1, class A2, class A3, class A4>
inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on> >::type(max)(const number<Backend, et_on>& a, const detail::expression<tag, A1, A2, A3, A4>& b)
{
number<Backend, et_on> t(b);
if (a > t)
return a;
return std::move(t);
}
template <class tag, class A1, class A2, class A3, class A4, class Backend>
inline typename std::enable_if<boost::multiprecision::detail::is_backend<Backend>::value, const number<Backend, et_on> >::type(max)(const detail::expression<tag, A1, A2, A3, A4>& a, const number<Backend, et_on>& b)
{
number<Backend, et_on> t(a);
if (t > b)
return std::move(t);
return b;
}
template <class tag, class A1, class A2, class A3, class A4, class tagb, class A1b, class A2b, class A3b, class A4b>
inline typename detail::expression<tag, A1, A2, A3, A4>::result_type(max)(const detail::expression<tag, A1, A2, A3, A4>& a, const detail::expression<tagb, A1b, A2b, A3b, A4b>& b)
{
typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
if (t1 > t2)
return std::move(t1);
return std::move(t2);
}
template <class tag, class A1, class A2, class A3, class A4>
inline typename detail::expression<tag, A1, A2, A3, A4>::result_type(max)(const detail::expression<tag, A1, A2, A3, A4>& a, const detail::expression<tag, A1, A2, A3, A4>& b)
{
typename detail::expression<tag, A1, A2, A3, A4>::result_type t1(a), t2(b);
if (t1 > t2)
return std::move(t1);
return std::move(t2);
}
}} // namespace boost::multiprecision
#endif
+661
View File
@@ -0,0 +1,661 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2012 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_MP_NO_ET_OPS_HPP
#define BOOST_MP_NO_ET_OPS_HPP
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4714)
#endif
namespace boost {
namespace multiprecision {
//
// Operators for non-expression template enabled number.
// NOTE: this is not a complete header - really just a suffix to default_ops.hpp.
// NOTE: these operators have to be defined after the methods in default_ops.hpp.
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator-(const number<B, et_off>& v)
{
static_assert(is_signed_number<B>::value, "Negating an unsigned type results in ill-defined behavior.");
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(v);
number<B, et_off> result(v);
result.backend().negate();
return result;
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator~(const number<B, et_off>& v)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(v);
number<B, et_off> result;
eval_complement(result.backend(), v.backend());
return result;
}
//
// Addition:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator+(const number<B, et_off>& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
number<B, et_off> result;
using default_ops::eval_add;
eval_add(result.backend(), a.backend(), b.backend());
return result;
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value, number<B, et_off> >::type
operator+(const number<B, et_off>& a, const V& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
number<B, et_off> result;
using default_ops::eval_add;
eval_add(result.backend(), a.backend(), number<B, et_off>::canonical_value(b));
return result;
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator+(const V& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(b, a);
number<B, et_off> result;
using default_ops::eval_add;
eval_add(result.backend(), b.backend(), number<B, et_off>::canonical_value(a));
return result;
}
//
// Subtraction:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator-(const number<B, et_off>& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
number<B, et_off> result;
using default_ops::eval_subtract;
eval_subtract(result.backend(), a.backend(), b.backend());
return result;
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value, number<B, et_off> >::type
operator-(const number<B, et_off>& a, const V& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
number<B, et_off> result;
using default_ops::eval_subtract;
eval_subtract(result.backend(), a.backend(), number<B, et_off>::canonical_value(b));
return result;
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator-(const V& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(b, a);
number<B, et_off> result;
using default_ops::eval_subtract;
eval_subtract(result.backend(), number<B, et_off>::canonical_value(a), b.backend());
return result;
}
//
// Multiply:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator*(const number<B, et_off>& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
number<B, et_off> result;
using default_ops::eval_multiply;
eval_multiply(result.backend(), a.backend(), b.backend());
return result;
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value, number<B, et_off> >::type
operator*(const number<B, et_off>& a, const V& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
number<B, et_off> result;
using default_ops::eval_multiply;
eval_multiply(result.backend(), a.backend(), number<B, et_off>::canonical_value(b));
return result;
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator*(const V& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(b, a);
number<B, et_off> result;
using default_ops::eval_multiply;
eval_multiply(result.backend(), b.backend(), number<B, et_off>::canonical_value(a));
return result;
}
//
// divide:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator/(const number<B, et_off>& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
number<B, et_off> result;
using default_ops::eval_divide;
eval_divide(result.backend(), a.backend(), b.backend());
return result;
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value, number<B, et_off> >::type
operator/(const number<B, et_off>& a, const V& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
number<B, et_off> result;
using default_ops::eval_divide;
eval_divide(result.backend(), a.backend(), number<B, et_off>::canonical_value(b));
return result;
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator/(const V& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(b, a);
number<B, et_off> result;
using default_ops::eval_divide;
eval_divide(result.backend(), number<B, et_off>::canonical_value(a), b.backend());
return result;
}
//
// modulus:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator%(const number<B, et_off>& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
number<B, et_off> result;
using default_ops::eval_modulus;
eval_modulus(result.backend(), a.backend(), b.backend());
return result;
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator%(const number<B, et_off>& a, const V& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a);
number<B, et_off> result;
using default_ops::eval_modulus;
eval_modulus(result.backend(), a.backend(), number<B, et_off>::canonical_value(b));
return result;
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer) && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator%(const V& a, const number<B, et_off>& b)
{
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(b);
number<B, et_off> result;
using default_ops::eval_modulus;
eval_modulus(result.backend(), number<B, et_off>::canonical_value(a), b.backend());
return result;
}
//
// Bitwise or:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator|(const number<B, et_off>& a, const number<B, et_off>& b)
{
number<B, et_off> result;
using default_ops::eval_bitwise_or;
eval_bitwise_or(result.backend(), a.backend(), b.backend());
return result;
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator|(const number<B, et_off>& a, const V& b)
{
number<B, et_off> result;
using default_ops::eval_bitwise_or;
eval_bitwise_or(result.backend(), a.backend(), number<B, et_off>::canonical_value(b));
return result;
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer) && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator|(const V& a, const number<B, et_off>& b)
{
number<B, et_off> result;
using default_ops::eval_bitwise_or;
eval_bitwise_or(result.backend(), b.backend(), number<B, et_off>::canonical_value(a));
return result;
}
//
// Bitwise xor:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator^(const number<B, et_off>& a, const number<B, et_off>& b)
{
number<B, et_off> result;
using default_ops::eval_bitwise_xor;
eval_bitwise_xor(result.backend(), a.backend(), b.backend());
return result;
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator^(const number<B, et_off>& a, const V& b)
{
number<B, et_off> result;
using default_ops::eval_bitwise_xor;
eval_bitwise_xor(result.backend(), a.backend(), number<B, et_off>::canonical_value(b));
return result;
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer) && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator^(const V& a, const number<B, et_off>& b)
{
number<B, et_off> result;
using default_ops::eval_bitwise_xor;
eval_bitwise_xor(result.backend(), b.backend(), number<B, et_off>::canonical_value(a));
return result;
}
//
// Bitwise and:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator&(const number<B, et_off>& a, const number<B, et_off>& b)
{
number<B, et_off> result;
using default_ops::eval_bitwise_and;
eval_bitwise_and(result.backend(), a.backend(), b.backend());
return result;
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator&(const number<B, et_off>& a, const V& b)
{
number<B, et_off> result;
using default_ops::eval_bitwise_and;
eval_bitwise_and(result.backend(), a.backend(), number<B, et_off>::canonical_value(b));
return result;
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer) && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator&(const V& a, const number<B, et_off>& b)
{
number<B, et_off> result;
using default_ops::eval_bitwise_and;
eval_bitwise_and(result.backend(), b.backend(), number<B, et_off>::canonical_value(a));
return result;
}
//
// shifts:
//
template <class B, class I>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_integral<I>::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator<<(const number<B, et_off>& a, const I& b)
{
number<B, et_off> result(a);
using default_ops::eval_left_shift;
detail::check_shift_range(b, std::integral_constant<bool, (sizeof(I) > sizeof(std::size_t))>(), std::integral_constant<bool, boost::multiprecision::detail::is_signed<I>::value>());
eval_left_shift(result.backend(), b);
return result;
}
template <class B, class I>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_integral<I>::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator>>(const number<B, et_off>& a, const I& b)
{
number<B, et_off> result(a);
using default_ops::eval_right_shift;
detail::check_shift_range(b, std::integral_constant<bool, (sizeof(I) > sizeof(std::size_t))>(), std::integral_constant<bool, boost::multiprecision::detail::is_signed<I>::value>());
eval_right_shift(result.backend(), b);
return result;
}
//
// If we have rvalue references go all over again with rvalue ref overloads and move semantics.
// Note that while it would be tempting to implement these so they return an rvalue reference
// (and indeed this would be optimally efficient), this is unsafe due to users propensity to
// write:
//
// const T& t = a * b;
//
// which would lead to a dangling reference if we didn't return by value. Of course move
// semantics help a great deal in return by value, so performance is still pretty good...
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator-(number<B, et_off>&& v)
{
static_assert(is_signed_number<B>::value, "Negating an unsigned type results in ill-defined behavior.");
v.backend().negate();
return std::move(v);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator~(number<B, et_off>&& v)
{
eval_complement(v.backend(), v.backend());
return std::move(v);
}
//
// Addition:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator+(number<B, et_off>&& a, const number<B, et_off>& b)
{
using default_ops::eval_add;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_add(a.backend(), b.backend());
return std::move(a);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator+(const number<B, et_off>& a, number<B, et_off>&& b)
{
using default_ops::eval_add;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_add(b.backend(), a.backend());
return std::move(b);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator+(number<B, et_off>&& a, number<B, et_off>&& b)
{
using default_ops::eval_add;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_add(a.backend(), b.backend());
return std::move(a);
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value, number<B, et_off> >::type
operator+(number<B, et_off>&& a, const V& b)
{
using default_ops::eval_add;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_add(a.backend(), number<B, et_off>::canonical_value(b));
return std::move(a);
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator+(const V& a, number<B, et_off>&& b)
{
using default_ops::eval_add;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_add(b.backend(), number<B, et_off>::canonical_value(a));
return std::move(b);
}
//
// Subtraction:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator-(number<B, et_off>&& a, const number<B, et_off>& b)
{
using default_ops::eval_subtract;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_subtract(a.backend(), b.backend());
return std::move(a);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_signed_number<B>::value, number<B, et_off> >::type operator-(const number<B, et_off>& a, number<B, et_off>&& b)
{
using default_ops::eval_subtract;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_subtract(b.backend(), a.backend());
b.backend().negate();
return std::move(b);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator-(number<B, et_off>&& a, number<B, et_off>&& b)
{
using default_ops::eval_subtract;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_subtract(a.backend(), b.backend());
return std::move(a);
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value, number<B, et_off> >::type
operator-(number<B, et_off>&& a, const V& b)
{
using default_ops::eval_subtract;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_subtract(a.backend(), number<B, et_off>::canonical_value(b));
return std::move(a);
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<(is_compatible_arithmetic_type<V, number<B, et_off> >::value && is_signed_number<B>::value) && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator-(const V& a, number<B, et_off>&& b)
{
using default_ops::eval_subtract;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_subtract(b.backend(), number<B, et_off>::canonical_value(a));
b.backend().negate();
return std::move(b);
}
//
// Multiply:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator*(number<B, et_off>&& a, const number<B, et_off>& b)
{
using default_ops::eval_multiply;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_multiply(a.backend(), b.backend());
return std::move(a);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator*(const number<B, et_off>& a, number<B, et_off>&& b)
{
using default_ops::eval_multiply;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_multiply(b.backend(), a.backend());
return std::move(b);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator*(number<B, et_off>&& a, number<B, et_off>&& b)
{
using default_ops::eval_multiply;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_multiply(a.backend(), b.backend());
return std::move(a);
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value, number<B, et_off> >::type
operator*(number<B, et_off>&& a, const V& b)
{
using default_ops::eval_multiply;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_multiply(a.backend(), number<B, et_off>::canonical_value(b));
return std::move(a);
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator*(const V& a, number<B, et_off>&& b)
{
using default_ops::eval_multiply;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_multiply(b.backend(), number<B, et_off>::canonical_value(a));
return std::move(b);
}
//
// divide:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR number<B, et_off> operator/(number<B, et_off>&& a, const number<B, et_off>& b)
{
using default_ops::eval_divide;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_divide(a.backend(), b.backend());
return std::move(a);
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value, number<B, et_off> >::type
operator/(number<B, et_off>&& a, const V& b)
{
using default_ops::eval_divide;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_divide(a.backend(), number<B, et_off>::canonical_value(b));
return std::move(a);
}
//
// modulus:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator%(number<B, et_off>&& a, const number<B, et_off>& b)
{
using default_ops::eval_modulus;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_modulus(a.backend(), b.backend());
return std::move(a);
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator%(number<B, et_off>&& a, const V& b)
{
using default_ops::eval_modulus;
detail::scoped_default_precision<multiprecision::number<B, et_off> > precision_guard(a, b);
eval_modulus(a.backend(), number<B, et_off>::canonical_value(b));
return std::move(a);
}
//
// Bitwise or:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator|(number<B, et_off>&& a, const number<B, et_off>& b)
{
using default_ops::eval_bitwise_or;
eval_bitwise_or(a.backend(), b.backend());
return std::move(a);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator|(const number<B, et_off>& a, number<B, et_off>&& b)
{
using default_ops::eval_bitwise_or;
eval_bitwise_or(b.backend(), a.backend());
return std::move(b);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator|(number<B, et_off>&& a, number<B, et_off>&& b)
{
using default_ops::eval_bitwise_or;
eval_bitwise_or(a.backend(), b.backend());
return std::move(a);
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator|(number<B, et_off>&& a, const V& b)
{
using default_ops::eval_bitwise_or;
eval_bitwise_or(a.backend(), number<B, et_off>::canonical_value(b));
return std::move(a);
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer) && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator|(const V& a, number<B, et_off>&& b)
{
using default_ops::eval_bitwise_or;
eval_bitwise_or(b.backend(), number<B, et_off>::canonical_value(a));
return std::move(b);
}
//
// Bitwise xor:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator^(number<B, et_off>&& a, const number<B, et_off>& b)
{
using default_ops::eval_bitwise_xor;
eval_bitwise_xor(a.backend(), b.backend());
return std::move(a);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator^(const number<B, et_off>& a, number<B, et_off>&& b)
{
using default_ops::eval_bitwise_xor;
eval_bitwise_xor(b.backend(), a.backend());
return std::move(b);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator^(number<B, et_off>&& a, number<B, et_off>&& b)
{
using default_ops::eval_bitwise_xor;
eval_bitwise_xor(a.backend(), b.backend());
return std::move(a);
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator^(number<B, et_off>&& a, const V& b)
{
using default_ops::eval_bitwise_xor;
eval_bitwise_xor(a.backend(), number<B, et_off>::canonical_value(b));
return std::move(a);
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer) && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator^(const V& a, number<B, et_off>&& b)
{
using default_ops::eval_bitwise_xor;
eval_bitwise_xor(b.backend(), number<B, et_off>::canonical_value(a));
return std::move(b);
}
//
// Bitwise and:
//
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator&(number<B, et_off>&& a, const number<B, et_off>& b)
{
using default_ops::eval_bitwise_and;
eval_bitwise_and(a.backend(), b.backend());
return std::move(a);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator&(const number<B, et_off>& a, number<B, et_off>&& b)
{
using default_ops::eval_bitwise_and;
eval_bitwise_and(b.backend(), a.backend());
return std::move(b);
}
template <class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<number_category<B>::value == number_kind_integer, number<B, et_off> >::type operator&(number<B, et_off>&& a, number<B, et_off>&& b)
{
using default_ops::eval_bitwise_and;
eval_bitwise_and(a.backend(), b.backend());
return std::move(a);
}
template <class B, class V>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator&(number<B, et_off>&& a, const V& b)
{
using default_ops::eval_bitwise_and;
eval_bitwise_and(a.backend(), number<B, et_off>::canonical_value(b));
return std::move(a);
}
template <class V, class B>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_compatible_arithmetic_type<V, number<B, et_off> >::value && (number_category<B>::value == number_kind_integer) && !is_equivalent_number_type<V, B>::value, number<B, et_off> >::type
operator&(const V& a, number<B, et_off>&& b)
{
using default_ops::eval_bitwise_and;
eval_bitwise_and(b.backend(), number<B, et_off>::canonical_value(a));
return std::move(b);
}
//
// shifts:
//
template <class B, class I>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_integral<I>::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator<<(number<B, et_off>&& a, const I& b)
{
using ui_type = typename boost::multiprecision::detail::make_unsigned<I>::type;
using default_ops::eval_left_shift;
eval_left_shift(a.backend(), static_cast<ui_type>(b));
return std::move(a);
}
template <class B, class I>
BOOST_MP_FORCEINLINE BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<boost::multiprecision::detail::is_integral<I>::value && (number_category<B>::value == number_kind_integer), number<B, et_off> >::type
operator>>(number<B, et_off>&& a, const I& b)
{
using ui_type = typename boost::multiprecision::detail::make_unsigned<I>::type;
using default_ops::eval_right_shift;
eval_right_shift(a.backend(), static_cast<ui_type>(b));
return std::move(a);
}
}
} // namespace boost::multiprecision
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif // BOOST_MP_NO_ET_OPS_HPP
@@ -0,0 +1,55 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2004 - 2021 Pavel Vozenilek.
// Copyright 2021 Matt Borland. 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_MP_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP
#define BOOST_MP_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP
#include <boost/multiprecision/detail/standalone_config.hpp>
#ifdef BOOST_MP_STANDALONE
#ifndef BOOST_NO_EXCEPTIONS
# define BOOST_MP_TRY { try
# define BOOST_MP_CATCH(x) catch(x)
# define BOOST_MP_RETHROW throw;
# define BOOST_MP_CATCH_END }
# define BOOST_MP_THROW_EXCEPTION(x) throw (x);
#else
# if !defined(BOOST_MSVC) || BOOST_MSVC >= 1900
# define BOOST_MP_TRY { if (true)
# define BOOST_MP_CATCH(x) else if (false)
# else
// warning C4127: conditional expression is constant
# define BOOST_MP_TRY { \
__pragma(warning(push)) \
__pragma(warning(disable: 4127)) \
if (true) \
__pragma(warning(pop))
# define BOOST_MP_CATCH(x) else \
__pragma(warning(push)) \
__pragma(warning(disable: 4127)) \
if (false) \
__pragma(warning(pop))
# endif
# define BOOST_MP_RETHROW
# define BOOST_MP_CATCH_END }
# define BOOST_MP_THROW_EXCEPTION(x) {static_cast<void>(x);}
#endif
#else // Not standalone mode
# include <boost/core/no_exceptions_support.hpp>
# include <boost/throw_exception.hpp>
# define BOOST_MP_TRY BOOST_TRY
# define BOOST_MP_CATCH(x) BOOST_CATCH(x)
# define BOOST_MP_RETHROW BOOST_RETHROW
# define BOOST_MP_CATCH_END BOOST_CATCH_END
# define BOOST_MP_THROW_EXCEPTION(x) BOOST_THROW_EXCEPTION(x)
#endif // BOOST_MP_STANDALONE
#endif // BOOST_MP_DETAIL_NO_EXCEPTIONS_SUPPORT_HPP
File diff suppressed because it is too large Load Diff
+848
View File
@@ -0,0 +1,848 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2012 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_MP_NUMBER_COMPARE_HPP
#define BOOST_MP_NUMBER_COMPARE_HPP
#include <boost/multiprecision/traits/is_backend.hpp>
#include <boost/multiprecision/detail/fpclassify.hpp>
//
// Comparison operators for number.
//
namespace boost { namespace multiprecision {
namespace default_ops {
//
// The dispatching mechanism used here to deal with differently typed arguments
// could be better replaced with enable_if overloads, but that breaks MSVC-12
// under strange and hard to reproduce circumstances.
//
template <class B>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_eq(const B& a, const B& b)
{
return a.compare(b) == 0;
}
template <class T, class U>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_eq_imp(const T& a, const U& b, const std::integral_constant<bool, true>&)
{
typename boost::multiprecision::detail::number_from_backend<T, U>::type t(b);
return eval_eq(a, t.backend());
}
template <class T, class U>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_eq_imp(const T& a, const U& b, const std::integral_constant<bool, false>&)
{
typename boost::multiprecision::detail::number_from_backend<U, T>::type t(a);
return eval_eq(t.backend(), b);
}
template <class T, class U>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_eq(const T& a, const U& b)
{
using tag_type = std::integral_constant<bool, boost::multiprecision::detail::is_first_backend<T, U>::value>;
return eval_eq_imp(a, b, tag_type());
}
template <class B>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_lt(const B& a, const B& b)
{
return a.compare(b) < 0;
}
template <class T, class U>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_lt_imp(const T& a, const U& b, const std::integral_constant<bool, true>&)
{
typename boost::multiprecision::detail::number_from_backend<T, U>::type t(b);
return eval_lt(a, t.backend());
}
template <class T, class U>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_lt_imp(const T& a, const U& b, const std::integral_constant<bool, false>&)
{
typename boost::multiprecision::detail::number_from_backend<U, T>::type t(a);
return eval_lt(t.backend(), b);
}
template <class T, class U>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_lt(const T& a, const U& b)
{
using tag_type = std::integral_constant<bool, boost::multiprecision::detail::is_first_backend<T, U>::value>;
return eval_lt_imp(a, b, tag_type());
}
template <class B>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_gt(const B& a, const B& b)
{
return a.compare(b) > 0;
}
template <class T, class U>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_gt_imp(const T& a, const U& b, const std::integral_constant<bool, true>&)
{
typename boost::multiprecision::detail::number_from_backend<T, U>::type t(b);
return eval_gt(a, t.backend());
}
template <class T, class U>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_gt_imp(const T& a, const U& b, const std::integral_constant<bool, false>&)
{
typename boost::multiprecision::detail::number_from_backend<U, T>::type t(a);
return eval_gt(t.backend(), b);
}
template <class T, class U>
inline BOOST_MP_CXX14_CONSTEXPR bool eval_gt(const T& a, const U& b)
{
using tag_type = std::integral_constant<bool, boost::multiprecision::detail::is_first_backend<T, U>::value>;
return eval_gt_imp(a, b, tag_type());
}
} // namespace default_ops
namespace detail {
template <class Num, class Val>
struct is_valid_mixed_compare : public std::integral_constant<bool, false>
{};
template <class B, expression_template_option ET, class Val>
struct is_valid_mixed_compare<number<B, ET>, Val> : public std::is_convertible<Val, number<B, ET> >
{};
template <class B, expression_template_option ET>
struct is_valid_mixed_compare<number<B, ET>, number<B, ET> > : public std::integral_constant<bool, false>
{};
template <class B, expression_template_option ET, class tag, class Arg1, class Arg2, class Arg3, class Arg4>
struct is_valid_mixed_compare<number<B, ET>, expression<tag, Arg1, Arg2, Arg3, Arg4> >
: public std::is_convertible<expression<tag, Arg1, Arg2, Arg3, Arg4>, number<B, ET> >
{};
template <class tag, class Arg1, class Arg2, class Arg3, class Arg4, class B, expression_template_option ET>
struct is_valid_mixed_compare<expression<tag, Arg1, Arg2, Arg3, Arg4>, number<B, ET> >
: public std::is_convertible<expression<tag, Arg1, Arg2, Arg3, Arg4>, number<B, ET> >
{};
template <class Backend, expression_template_option ExpressionTemplates>
inline constexpr typename std::enable_if<number_category<Backend>::value != number_kind_floating_point, bool>::type is_unordered_value(const number<Backend, ExpressionTemplates>&)
{
return false;
}
template <class Backend, expression_template_option ExpressionTemplates>
inline constexpr typename std::enable_if<number_category<Backend>::value == number_kind_floating_point, bool>::type is_unordered_value(const number<Backend, ExpressionTemplates>& a)
{
using default_ops::eval_fpclassify;
return eval_fpclassify(a.backend()) == FP_NAN;
}
template <class Arithmetic>
inline constexpr typename std::enable_if<number_category<Arithmetic>::value != number_kind_floating_point, bool>::type is_unordered_value(const Arithmetic&)
{
return false;
}
template <class Arithmetic>
inline
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
BOOST_MP_CXX14_CONSTEXPR
#endif
typename std::enable_if < number_category < Arithmetic> ::value == number_kind_floating_point, bool> ::type
is_unordered_value(const Arithmetic& a)
{
#ifndef BOOST_MP_NO_CONSTEXPR_DETECTION
if (BOOST_MP_IS_CONST_EVALUATED(a))
{
return a != a;
}
else
#endif
{
return BOOST_MP_ISNAN(a);
}
}
template <class T, class U>
inline constexpr bool is_unordered_comparison(const T& a, const U& b)
{
return is_unordered_value(a) || is_unordered_value(b);
}
} // namespace detail
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR bool operator==(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b)
{
using default_ops::eval_eq;
if (detail::is_unordered_comparison(a, b))
return false;
return eval_eq(a.backend(), b.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && !is_number_expression<Arithmetic>::value, bool>::type
operator==(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b)
{
using default_ops::eval_eq;
if (detail::is_unordered_comparison(a, b))
return false;
return eval_eq(a.backend(), number<Backend, ExpressionTemplates>::canonical_value(b));
}
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && !is_number_expression<Arithmetic>::value, bool>::type
operator==(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b)
{
using default_ops::eval_eq;
if (detail::is_unordered_comparison(a, b))
return false;
return eval_eq(b.backend(), number<Backend, ExpressionTemplates>::canonical_value(a));
}
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
operator==(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_eq;
result_type t(b);
if (detail::is_unordered_comparison(a, t))
return false;
return eval_eq(t.backend(), result_type::canonical_value(a));
}
template <class Backend, expression_template_option ExpressionTemplates, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR bool operator==(const number<Backend, ExpressionTemplates>& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_eq;
result_type t(b);
if (detail::is_unordered_comparison(a, t))
return false;
return eval_eq(t.backend(), a.backend());
}
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
operator==(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_eq;
result_type t(a);
if (detail::is_unordered_comparison(t, b))
return false;
return eval_eq(t.backend(), result_type::canonical_value(b));
}
template <class Tag, class A1, class A2, class A3, class A4, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR bool operator==(const detail::expression<Tag, A1, A2, A3, A4>& a, const number<Backend, ExpressionTemplates>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_eq;
result_type t(a);
if (detail::is_unordered_comparison(t, b))
return false;
return eval_eq(t.backend(), b.backend());
}
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value, bool>::type
operator==(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b)
{
using default_ops::eval_eq;
typename detail::expression<Tag, A1, A2, A3, A4>::result_type t(a);
typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type t2(b);
if (detail::is_unordered_comparison(t, t2))
return false;
return eval_eq(t.backend(), t2.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR bool operator!=(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b)
{
using default_ops::eval_eq;
if (detail::is_unordered_comparison(a, b))
return true;
return !eval_eq(a.backend(), b.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && !is_number_expression<Arithmetic>::value, bool>::type
operator!=(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b)
{
using default_ops::eval_eq;
if (detail::is_unordered_comparison(a, b))
return true;
return !eval_eq(a.backend(), number<Backend, et_on>::canonical_value(b));
}
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && !is_number_expression<Arithmetic>::value, bool>::type
operator!=(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b)
{
using default_ops::eval_eq;
if (detail::is_unordered_comparison(a, b))
return true;
return !eval_eq(b.backend(), number<Backend, et_on>::canonical_value(a));
}
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
operator!=(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_eq;
result_type t(b);
if (detail::is_unordered_comparison(a, t))
return true;
return !eval_eq(t.backend(), result_type::canonical_value(a));
}
template <class Backend, expression_template_option ExpressionTemplates, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR bool operator!=(const number<Backend, ExpressionTemplates>& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_eq;
result_type t(b);
if (detail::is_unordered_comparison(a, t))
return true;
return !eval_eq(t.backend(), a.backend());
}
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
operator!=(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_eq;
result_type t(a);
if (detail::is_unordered_comparison(t, b))
return true;
return !eval_eq(t.backend(), result_type::canonical_value(b));
}
template <class Tag, class A1, class A2, class A3, class A4, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR bool operator!=(const detail::expression<Tag, A1, A2, A3, A4>& a, const number<Backend, ExpressionTemplates>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_eq;
result_type t(a);
if (detail::is_unordered_comparison(t, b))
return true;
return !eval_eq(t.backend(), result_type::canonical_value(b));
}
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value, bool>::type
operator!=(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b)
{
using default_ops::eval_eq;
typename detail::expression<Tag, A1, A2, A3, A4>::result_type t(a);
typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type t2(b);
if (detail::is_unordered_comparison(t, t2))
return true;
return !eval_eq(t.backend(), t2.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<(number_category<Backend>::value != number_kind_complex) && (number_category<Backend2>::value != number_kind_complex), bool>::type
operator<(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b)
{
using default_ops::eval_lt;
if (detail::is_unordered_comparison(a, b))
return false;
return eval_lt(a.backend(), b.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && (number_category<Backend>::value != number_kind_complex) && !is_number_expression<Arithmetic>::value, bool>::type
operator<(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b)
{
using default_ops::eval_lt;
if (detail::is_unordered_comparison(a, b))
return false;
return eval_lt(a.backend(), number<Backend, ExpressionTemplates>::canonical_value(b));
}
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && (number_category<Backend>::value != number_kind_complex) && !is_number_expression<Arithmetic>::value, bool>::type
operator<(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b)
{
using default_ops::eval_gt;
if (detail::is_unordered_comparison(a, b))
return false;
return eval_gt(b.backend(), number<Backend, ExpressionTemplates>::canonical_value(a));
}
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator<(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_gt;
result_type t(b);
if (detail::is_unordered_comparison(a, t))
return false;
return eval_gt(t.backend(), result_type::canonical_value(a));
}
template <class Backend, expression_template_option ExpressionTemplates, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR bool operator<(const number<Backend, ExpressionTemplates>& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_gt;
result_type t(b);
return a < t;
}
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator<(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_lt;
result_type t(a);
if (detail::is_unordered_comparison(t, b))
return false;
return eval_lt(t.backend(), result_type::canonical_value(b));
}
template <class Tag, class A1, class A2, class A3, class A4, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR bool operator<(const detail::expression<Tag, A1, A2, A3, A4>& a, const number<Backend, ExpressionTemplates>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_lt;
result_type t(a);
return t < b;
}
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator<(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b)
{
using default_ops::eval_lt;
typename detail::expression<Tag, A1, A2, A3, A4>::result_type t(a);
typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type t2(b);
if (detail::is_unordered_comparison(t, t2))
return false;
return eval_lt(t.backend(), t2.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<(number_category<Backend>::value != number_kind_complex) && (number_category<Backend2>::value != number_kind_complex), bool>::type
operator>(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b)
{
using default_ops::eval_gt;
if (detail::is_unordered_comparison(a, b))
return false;
return eval_gt(a.backend(), b.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && (number_category<Backend>::value != number_kind_complex) && !is_number_expression<Arithmetic>::value, bool>::type
operator>(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b)
{
using default_ops::eval_gt;
if (detail::is_unordered_comparison(a, b))
return false;
return eval_gt(a.backend(), number<Backend, ExpressionTemplates>::canonical_value(b));
}
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && (number_category<Backend>::value != number_kind_complex) && !is_number_expression<Arithmetic>::value, bool>::type
operator>(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b)
{
using default_ops::eval_lt;
if (detail::is_unordered_comparison(a, b))
return false;
return eval_lt(b.backend(), number<Backend, ExpressionTemplates>::canonical_value(a));
}
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator>(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_lt;
result_type t(b);
return a > t;
}
template <class Backend, expression_template_option ExpressionTemplates, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR bool operator>(const number<Backend, ExpressionTemplates>& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_lt;
result_type t(b);
return a > t;
}
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator>(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_gt;
result_type t(a);
return t > b;
}
template <class Tag, class A1, class A2, class A3, class A4, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR bool operator>(const detail::expression<Tag, A1, A2, A3, A4>& a, const number<Backend, ExpressionTemplates>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_gt;
result_type t(a);
return t > b;
}
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator>(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b)
{
using default_ops::eval_gt;
typename detail::expression<Tag, A1, A2, A3, A4>::result_type t(a);
typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type t2(b);
return t > t2;
}
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<(number_category<Backend>::value != number_kind_complex) && (number_category<Backend2>::value != number_kind_complex), bool>::type
operator<=(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b)
{
using default_ops::eval_gt;
if (detail::is_unordered_comparison(a, b))
return false;
return !eval_gt(a.backend(), b.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && (number_category<Backend>::value != number_kind_complex) && !is_number_expression<Arithmetic>::value, bool>::type
operator<=(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b)
{
using default_ops::eval_gt;
if (detail::is_unordered_comparison(a, b))
return false;
return !eval_gt(a.backend(), number<Backend, ExpressionTemplates>::canonical_value(b));
}
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && (number_category<Backend>::value != number_kind_complex) && !is_number_expression<Arithmetic>::value, bool>::type
operator<=(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b)
{
using default_ops::eval_lt;
if (detail::is_unordered_comparison(a, b))
return false;
return !eval_lt(b.backend(), number<Backend, ExpressionTemplates>::canonical_value(a));
}
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator<=(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_lt;
if (detail::is_unordered_value(a) || detail::is_unordered_value(b))
return false;
result_type t(b);
if (detail::is_unordered_comparison(a, t))
return false;
return !eval_lt(t.backend(), result_type::canonical_value(a));
}
template <class Backend, expression_template_option ExpressionTemplates, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR bool operator<=(const number<Backend, ExpressionTemplates>& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_lt;
if (detail::is_unordered_value(a) || detail::is_unordered_value(b))
return false;
result_type t(b);
return a <= t;
}
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator<=(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_gt;
result_type t(a);
if (detail::is_unordered_comparison(t, b))
return false;
return !eval_gt(t.backend(), result_type::canonical_value(b));
}
template <class Tag, class A1, class A2, class A3, class A4, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR bool operator<=(const detail::expression<Tag, A1, A2, A3, A4>& a, const number<Backend, ExpressionTemplates>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_gt;
result_type t(a);
return t <= b;
}
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator<=(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b)
{
using default_ops::eval_gt;
typename detail::expression<Tag, A1, A2, A3, A4>::result_type t(a);
typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type t2(b);
if (detail::is_unordered_comparison(t, t2))
return false;
return !eval_gt(t.backend(), t2.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<(number_category<Backend>::value != number_kind_complex) && (number_category<Backend2>::value != number_kind_complex), bool>::type
operator>=(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b)
{
using default_ops::eval_lt;
if (detail::is_unordered_comparison(a, b))
return false;
return !eval_lt(a.backend(), b.backend());
}
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && (number_category<Backend>::value != number_kind_complex) && !is_number_expression<Arithmetic>::value, bool>::type
operator>=(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b)
{
using default_ops::eval_lt;
if (detail::is_unordered_comparison(a, b))
return false;
return !eval_lt(a.backend(), number<Backend, ExpressionTemplates>::canonical_value(b));
}
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value && (number_category<Backend>::value != number_kind_complex) && !is_number_expression<Arithmetic>::value, bool>::type
operator>=(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b)
{
using default_ops::eval_gt;
if (detail::is_unordered_comparison(a, b))
return false;
return !eval_gt(b.backend(), number<Backend, ExpressionTemplates>::canonical_value(a));
}
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator>=(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_gt;
result_type t(b);
if (detail::is_unordered_comparison(a, t))
return false;
return !eval_gt(t.backend(), result_type::canonical_value(a));
}
template <class Backend, expression_template_option ExpressionTemplates, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR bool operator>=(const number<Backend, ExpressionTemplates>& a, const detail::expression<Tag, A1, A2, A3, A4>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_gt;
result_type t(b);
return a >= t;
}
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator>=(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_lt;
result_type t(a);
if (detail::is_unordered_comparison(t, b))
return false;
return !eval_lt(t.backend(), result_type::canonical_value(b));
}
template <class Tag, class A1, class A2, class A3, class A4, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR bool operator>=(const detail::expression<Tag, A1, A2, A3, A4>& a, const number<Backend, ExpressionTemplates>& b)
{
using result_type = typename detail::expression<Tag, A1, A2, A3, A4>::result_type;
using default_ops::eval_lt;
result_type t(a);
return t >= b;
}
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value && (number_category<typename detail::expression<Tag, A1, A2, A3, A4>::result_type>::value != number_kind_complex), bool>::type
operator>=(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b)
{
using default_ops::eval_lt;
typename detail::expression<Tag, A1, A2, A3, A4>::result_type t(a);
typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type t2(b);
if (detail::is_unordered_comparison(t, t2))
return false;
return !eval_lt(t.backend(), t2.backend());
}
//
// C99 comparison macros as functions:
//
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR bool isgreater BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b) { return a > b; }
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
isgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b) { return a > b; }
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
isgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b) { return a > b; }
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
isgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b) { return a > b; }
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
isgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b) { return a > b; }
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value, bool>::type
isgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b) { return a > b; }
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR bool isgreaterequal BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b) { return a >= b; }
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
isgreaterequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b) { return a >= b; }
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
isgreaterequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b) { return a >= b; }
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
isgreaterequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b) { return a >= b; }
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
isgreaterequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b) { return a >= b; }
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value, bool>::type
isgreaterequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b) { return a >= b; }
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR bool islessequal BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b) { return a <= b; }
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
islessequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b) { return a <= b; }
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
islessequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b) { return a <= b; }
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
islessequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b) { return a <= b; }
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
islessequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b) { return a <= b; }
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value, bool>::type
islessequal
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b) { return a <= b; }
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR bool isless BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b) { return a < b; }
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
isless
BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b) { return a < b; }
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
isless
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b) { return a < b; }
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
isless
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& b) { return a < b; }
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
isless
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& a, const Arithmetic& b) { return a < b; }
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value, bool>::type
isless
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& a, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& b) { return a < b; }
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR bool islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b)
{
if (detail::is_unordered_comparison(a, b))
return false;
return a != b;
}
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
islessgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b)
{
if (detail::is_unordered_comparison(a, b))
return false;
return a != b;
}
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
islessgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b)
{
if (detail::is_unordered_comparison(a, b))
return false;
return a != b;
}
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
islessgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& bb)
{
typename detail::expression<Tag, A1, A2, A3, A4>::result_type b(bb);
return islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION(a, b);
}
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
islessgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& aa, const Arithmetic& b)
{
typename detail::expression<Tag, A1, A2, A3, A4>::result_type a(aa);
return islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION(a, b);
}
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value, bool>::type
islessgreater
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& aa, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& bb)
{
typename detail::expression<Tag, A1, A2, A3, A4>::result_type a(aa);
typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type b(bb);
return islessgreater BOOST_PREVENT_MACRO_SUBSTITUTION(a, b);
}
template <class Backend, expression_template_option ExpressionTemplates, class Backend2, expression_template_option ExpressionTemplates2>
inline BOOST_MP_CXX14_CONSTEXPR bool isunordered BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const number<Backend2, ExpressionTemplates2>& b) { return detail::is_unordered_comparison(a, b); }
template <class Backend, expression_template_option ExpressionTemplates, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
isunordered
BOOST_PREVENT_MACRO_SUBSTITUTION(const number<Backend, ExpressionTemplates>& a, const Arithmetic& b) { return detail::is_unordered_comparison(a, b); }
template <class Arithmetic, class Backend, expression_template_option ExpressionTemplates>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<number<Backend, ExpressionTemplates>, Arithmetic>::value, bool>::type
isunordered
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const number<Backend, ExpressionTemplates>& b) { return detail::is_unordered_comparison(a, b); }
template <class Arithmetic, class Tag, class A1, class A2, class A3, class A4>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
isunordered
BOOST_PREVENT_MACRO_SUBSTITUTION(const Arithmetic& a, const detail::expression<Tag, A1, A2, A3, A4>& bb)
{
typename detail::expression<Tag, A1, A2, A3, A4>::result_type b(bb);
return detail::is_unordered_comparison(a, b);
}
template <class Tag, class A1, class A2, class A3, class A4, class Arithmetic>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<detail::is_valid_mixed_compare<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, Arithmetic>::value, bool>::type
isunordered
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& aa, const Arithmetic& b)
{
typename detail::expression<Tag, A1, A2, A3, A4>::result_type a(aa);
return detail::is_unordered_comparison(a, b);
}
template <class Tag, class A1, class A2, class A3, class A4, class Tagb, class A1b, class A2b, class A3b, class A4b>
inline BOOST_MP_CXX14_CONSTEXPR typename std::enable_if<is_equivalent_number_type<typename detail::expression<Tag, A1, A2, A3, A4>::result_type, typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type>::value, bool>::type
isunordered
BOOST_PREVENT_MACRO_SUBSTITUTION(const detail::expression<Tag, A1, A2, A3, A4>& aa, const detail::expression<Tagb, A1b, A2b, A3b, A4b>& bb)
{
typename detail::expression<Tag, A1, A2, A3, A4>::result_type a(aa);
typename detail::expression<Tagb, A1b, A2b, A3b, A4b>::result_type b(bb);
return detail::is_unordered_comparison(a, b);
}
}} // namespace boost::multiprecision
#endif // BOOST_MP_NUMBER_COMPARE_HPP
+313
View File
@@ -0,0 +1,313 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2018 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_MP_DETAIL_PRECISION_HPP
#define BOOST_MP_DETAIL_PRECISION_HPP
#include <boost/multiprecision/traits/is_variable_precision.hpp>
#include <boost/multiprecision/detail/number_base.hpp>
#include <boost/multiprecision/detail/digits.hpp>
#include <boost/multiprecision/detail/assert.hpp>
namespace boost { namespace multiprecision { namespace detail {
template <class B, boost::multiprecision::expression_template_option ET>
inline constexpr unsigned current_precision_of_last_chance_imp(const boost::multiprecision::number<B, ET>&, const std::integral_constant<int, 0>&)
{
return std::numeric_limits<boost::multiprecision::number<B, ET> >::digits10;
}
template <class B, boost::multiprecision::expression_template_option ET>
inline BOOST_MP_CXX14_CONSTEXPR unsigned current_precision_of_last_chance_imp(const boost::multiprecision::number<B, ET>& val, const std::integral_constant<int, 1>&)
{
//
// We have an arbitrary precision integer, take it's "precision" as the
// location of the most-significant-bit less the location of the
// least-significant-bit, ie the number of bits required to represent the
// the value assuming we will have an exponent to shift things by:
//
return static_cast<unsigned>(val.is_zero() ? 1 : 1 + digits2_2_10(msb(abs(val)) - lsb(abs(val)) + 1));
}
template <class B, boost::multiprecision::expression_template_option ET>
inline BOOST_MP_CXX14_CONSTEXPR unsigned current_precision_of_last_chance_imp(const boost::multiprecision::number<B, ET>& val, const std::integral_constant<int, 2>&)
{
//
// We have an arbitrary precision rational, take it's "precision" as the
// the larger of the "precision" of numerator and denominator:
//
return (std::max)(current_precision_of_last_chance_imp(numerator(val), std::integral_constant<int, 1>()), current_precision_of_last_chance_imp(denominator(val), std::integral_constant<int, 1>()));
}
template <class B, boost::multiprecision::expression_template_option ET>
inline BOOST_MP_CXX14_CONSTEXPR unsigned current_precision_of_imp(const boost::multiprecision::number<B, ET>& n, const std::integral_constant<bool, true>&)
{
return n.precision();
}
template <class B, boost::multiprecision::expression_template_option ET>
inline constexpr unsigned current_precision_of_imp(const boost::multiprecision::number<B, ET>& val, const std::integral_constant<bool, false>&)
{
using tag = std::integral_constant<int,
std::numeric_limits<boost::multiprecision::number<B, ET> >::is_specialized &&
std::numeric_limits<boost::multiprecision::number<B, ET> >::is_integer &&
std::numeric_limits<boost::multiprecision::number<B, ET> >::is_exact &&
!std::numeric_limits<boost::multiprecision::number<B, ET> >::is_modulo
? 1
: boost::multiprecision::number_category<boost::multiprecision::number<B, ET> >::value == boost::multiprecision::number_kind_rational ? 2
: 0>;
return current_precision_of_last_chance_imp(val, tag());
}
template <class R, class Terminal>
inline constexpr unsigned current_precision_of_terminal(const Terminal&)
{
return (R::thread_default_variable_precision_options() >= variable_precision_options::preserve_all_precision)
? (std::numeric_limits<Terminal>::min_exponent ? std::numeric_limits<Terminal>::digits10 : 1 + std::numeric_limits<Terminal>::digits10) : 0;
}
template <class R, class Terminal>
inline constexpr unsigned current_precision_of(const Terminal& r)
{
return current_precision_of_terminal<R>(R::canonical_value(r));
}
template <class R>
inline constexpr unsigned current_precision_of(const float&)
{
using list = typename R::backend_type::float_types;
using first_float = typename std::tuple_element<0, list>::type;
return (R::thread_default_variable_precision_options() >= variable_precision_options::preserve_all_precision) ? std::numeric_limits<first_float>::digits10 : 0;
}
template <class R, class Terminal, std::size_t N>
inline constexpr unsigned current_precision_of(const Terminal (&)[N])
{ // For string literals:
return 0;
}
template <class R, class B, boost::multiprecision::expression_template_option ET>
inline constexpr unsigned current_precision_of_imp(const boost::multiprecision::number<B, ET>& n, const std::true_type&)
{
return std::is_same<R, boost::multiprecision::number<B, ET> >::value
|| (std::is_same<typename R::value_type, boost::multiprecision::number<B, ET> >::value && (R::thread_default_variable_precision_options() >= variable_precision_options::preserve_component_precision))
|| (R::thread_default_variable_precision_options() >= variable_precision_options::preserve_all_precision)
? current_precision_of_imp(n, boost::multiprecision::detail::is_variable_precision<boost::multiprecision::number<B, ET> >()) : 0;
}
template <class R, class B, boost::multiprecision::expression_template_option ET>
inline constexpr unsigned current_precision_of_imp(const boost::multiprecision::number<B, ET>& n, const std::false_type&)
{
return std::is_same<R, boost::multiprecision::number<B, ET> >::value
|| std::is_same<typename R::value_type, boost::multiprecision::number<B, ET> >::value
? current_precision_of_imp(n, boost::multiprecision::detail::is_variable_precision<boost::multiprecision::number<B, ET> >()) : 0;
}
template <class R, class B, boost::multiprecision::expression_template_option ET>
inline constexpr unsigned current_precision_of(const boost::multiprecision::number<B, ET>& n)
{
return current_precision_of_imp<R>(n, boost::multiprecision::detail::is_variable_precision<R>());
}
template <class R, class tag, class Arg1>
inline constexpr unsigned current_precision_of(const expression<tag, Arg1, void, void, void>& expr)
{
return current_precision_of<R>(expr.left_ref());
}
template <class R, class Arg1>
inline constexpr unsigned current_precision_of(const expression<terminal, Arg1, void, void, void>& expr)
{
return current_precision_of<R>(expr.value());
}
template <class R, class tag, class Arg1, class Arg2>
inline constexpr unsigned current_precision_of(const expression<tag, Arg1, Arg2, void, void>& expr)
{
return (std::max)(current_precision_of<R>(expr.left_ref()), current_precision_of<R>(expr.right_ref()));
}
template <class R, class tag, class Arg1, class Arg2, class Arg3>
inline constexpr unsigned current_precision_of(const expression<tag, Arg1, Arg2, Arg3, void>& expr)
{
return (std::max)((std::max)(current_precision_of<R>(expr.left_ref()), current_precision_of<R>(expr.right_ref())), current_precision_of<R>(expr.middle_ref()));
}
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4130)
#endif
template <class R, bool = boost::multiprecision::detail::is_variable_precision<R>::value>
struct scoped_default_precision
{
template <class T>
constexpr scoped_default_precision(const T&) {}
template <class T, class U>
constexpr scoped_default_precision(const T&, const U&) {}
template <class T, class U, class V>
constexpr scoped_default_precision(const T&, const U&, const V&) {}
//
// This function is never called: in C++17 it won't be compiled either:
//
unsigned precision() const
{
BOOST_MP_ASSERT("This function should never be called!!" == nullptr);
return 0;
}
};
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
template <class R>
struct scoped_default_precision<R, true>
{
template <class T>
BOOST_MP_CXX14_CONSTEXPR scoped_default_precision(const T& a)
{
init(has_uniform_precision() ? R::thread_default_precision() : (std::max)(R::thread_default_precision(), current_precision_of<R>(a)));
}
template <class T, class U>
BOOST_MP_CXX14_CONSTEXPR scoped_default_precision(const T& a, const U& b)
{
init(has_uniform_precision() ? R::thread_default_precision() : (std::max)(R::thread_default_precision(), (std::max)(current_precision_of<R>(a), current_precision_of<R>(b))));
}
template <class T, class U, class V>
BOOST_MP_CXX14_CONSTEXPR scoped_default_precision(const T& a, const U& b, const V& c)
{
init(has_uniform_precision() ? R::thread_default_precision() : (std::max)((std::max)(current_precision_of<R>(a), current_precision_of<R>(b)), (std::max)(R::thread_default_precision(), current_precision_of<R>(c))));
}
~scoped_default_precision()
{
if(m_new_prec != m_old_prec)
R::thread_default_precision(m_old_prec);
}
BOOST_MP_CXX14_CONSTEXPR unsigned precision() const
{
return m_new_prec;
}
static constexpr bool has_uniform_precision()
{
return R::thread_default_variable_precision_options() <= boost::multiprecision::variable_precision_options::assume_uniform_precision;
}
private:
BOOST_MP_CXX14_CONSTEXPR void init(unsigned p)
{
m_old_prec = R::thread_default_precision();
if (p && (p != m_old_prec))
{
R::thread_default_precision(p);
m_new_prec = p;
}
else
m_new_prec = m_old_prec;
}
unsigned m_old_prec, m_new_prec;
};
template <class T>
inline BOOST_MP_CXX14_CONSTEXPR void maybe_promote_precision(T*, const std::integral_constant<bool, false>&) {}
template <class T>
inline BOOST_MP_CXX14_CONSTEXPR void maybe_promote_precision(T* obj, const std::integral_constant<bool, true>&)
{
if (obj->precision() != T::thread_default_precision())
{
obj->precision(T::thread_default_precision());
}
}
template <class T>
inline BOOST_MP_CXX14_CONSTEXPR void maybe_promote_precision(T* obj)
{
maybe_promote_precision(obj, std::integral_constant<bool, boost::multiprecision::detail::is_variable_precision<T>::value>());
}
#ifndef BOOST_NO_CXX17_IF_CONSTEXPR
#define BOOST_MP_CONSTEXPR_IF_VARIABLE_PRECISION(T) \
if \
constexpr(boost::multiprecision::detail::is_variable_precision<T>::value)
#else
#define BOOST_MP_CONSTEXPR_IF_VARIABLE_PRECISION(T) if (boost::multiprecision::detail::is_variable_precision<T>::value)
#endif
template <class T, bool = boost::multiprecision::detail::is_variable_precision<T>::value>
struct scoped_target_precision
{
variable_precision_options opts;
scoped_target_precision() : opts(T::thread_default_variable_precision_options())
{
T::thread_default_variable_precision_options(variable_precision_options::preserve_target_precision);
}
~scoped_target_precision()
{
T::thread_default_variable_precision_options(opts);
}
};
template <class T>
struct scoped_target_precision<T, false> {};
template <class T, bool = boost::multiprecision::detail::is_variable_precision<T>::value>
struct scoped_source_precision
{
variable_precision_options opts;
scoped_source_precision() : opts(T::thread_default_variable_precision_options())
{
T::thread_default_variable_precision_options(variable_precision_options::preserve_source_precision);
}
~scoped_source_precision()
{
T::thread_default_variable_precision_options(opts);
}
};
template <class T>
struct scoped_source_precision<T, false> {};
template <class T, bool = boost::multiprecision::detail::is_variable_precision<T>::value>
struct scoped_precision_options
{
unsigned saved_digits;
boost::multiprecision::variable_precision_options saved_options;
scoped_precision_options(unsigned digits)
: saved_digits(T::thread_default_precision()), saved_options(T::thread_default_variable_precision_options())
{
T::thread_default_precision(digits);
}
scoped_precision_options(unsigned digits, variable_precision_options opts)
: saved_digits(T::thread_default_precision()), saved_options(T::thread_default_variable_precision_options())
{
T::thread_default_precision(digits);
T::thread_default_variable_precision_options(opts);
}
template <class U>
scoped_precision_options(const U& u)
: saved_digits(T::thread_default_precision()), saved_options(T::thread_default_variable_precision_options())
{
T::thread_default_precision(u.precision());
T::thread_default_variable_precision_options(U::thread_default_variable_precision_options());
}
~scoped_precision_options()
{
T::thread_default_variable_precision_options(saved_options);
T::thread_default_precision(saved_digits);
}
};
template <class T>
struct scoped_precision_options<T, false>
{
scoped_precision_options(unsigned) {}
scoped_precision_options(unsigned, variable_precision_options) {}
template <class U>
scoped_precision_options(const U&) {}
~scoped_precision_options() {}
};
}
}
} // namespace boost::multiprecision::detail
#endif // BOOST_MP_DETAIL_PRECISION_HPP
+19
View File
@@ -0,0 +1,19 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2012 John Maddock.
// Copyright Christopher Kormanyos 2013. 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_MP_DETAIL_REBIND_HPP
#define BOOST_MP_DETAIL_REBIND_HPP
namespace boost { namespace multiprecision { namespace backends { namespace detail {
template <class value_type, class my_allocator>
struct rebind
{
using type = typename std::allocator_traits<my_allocator>::template rebind_alloc<value_type>;
};
}}}} // namespace boost::multiprecision::backends::detail
#endif // BOOST_MP_DETAIL_REBIND_HPP
+148
View File
@@ -0,0 +1,148 @@
///////////////////////////////////////////////////////////////
// Copyright 2010 - 2021 Douglas Gregor
// 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
//
// Used to support configuration options depending on standalone context
// by providing either required support or disabling functionality
#ifndef BOOST_MP_STANDALONE_CONFIG_HPP
#define BOOST_MP_STANDALONE_CONFIG_HPP
#include <climits>
// Boost.Config is dependency free so it is considered a requirement to use Boost.Multiprecision in standalone mode
#ifdef __has_include
# if __has_include(<boost/config.hpp>)
# include <boost/config.hpp>
# include <boost/config/workaround.hpp>
# else
# error "Boost.Config is considered a requirement to use Boost.Multiprecision in standalone mode. A package is provided at https://github.com/boostorg/multiprecision/releases"
# endif
#else
// Provides the less helpful fatal error: 'boost/config.hpp' file not found if not available
# include <boost/config.hpp>
# include <boost/config/workaround.hpp>
#endif
// Minimum language standard transition
#ifdef _MSVC_LANG
# if _MSVC_LANG < 201402L
# pragma warning("The minimum language standard to use Boost.Math will be C++14 starting in July 2023 (Boost 1.82 release)");
# endif
#else
# if __cplusplus < 201402L
# warning "The minimum language standard to use Boost.Math will be C++14 starting in July 2023 (Boost 1.82 release)"
# endif
#endif
// If any of the most frequently used boost headers are missing assume that standalone mode is supposed to be used
#ifdef __has_include
#if !__has_include(<boost/assert.hpp>) || !__has_include(<boost/lexical_cast.hpp>) || \
!__has_include(<boost/throw_exception.hpp>) || !__has_include(<boost/predef/other/endian.h>)
# ifndef BOOST_MP_STANDALONE
# define BOOST_MP_STANDALONE
# endif
#endif
#endif
#ifndef BOOST_MP_STANDALONE
#include <boost/integer.hpp>
#include <boost/integer_traits.hpp>
// Required typedefs for interoperability with standalone mode
#if defined(BOOST_HAS_INT128) && defined(__cplusplus)
namespace boost { namespace multiprecision {
using int128_type = boost::int128_type;
using uint128_type = boost::uint128_type;
}}
#endif
#if defined(BOOST_HAS_FLOAT128) && defined(__cplusplus)
namespace boost { namespace multiprecision {
using float128_type = boost::float128_type;
}}
#endif
// Boost.Math available by default
#define BOOST_MP_MATH_AVAILABLE
#else // Standalone mode
#ifdef BOOST_MATH_STANDALONE
# define BOOST_MP_MATH_AVAILABLE
#endif
#ifndef BOOST_MP_MATH_AVAILABLE
# define BOOST_MATH_INSTRUMENT_CODE(x)
#endif
// Prevent Macro sub
#ifndef BOOST_PREVENT_MACRO_SUBSTITUTION
# define BOOST_PREVENT_MACRO_SUBSTITUTION
#endif
#if defined(BOOST_HAS_INT128) && defined(__cplusplus)
namespace boost { namespace multiprecision {
# ifdef __GNUC__
__extension__ typedef __int128 int128_type;
__extension__ typedef unsigned __int128 uint128_type;
# else
typedef __int128 int128_type;
typedef unsigned __int128 uint128_type;
# endif
}}
#endif
// same again for __float128:
#if defined(BOOST_HAS_FLOAT128) && defined(__cplusplus)
namespace boost { namespace multiprecision {
# ifdef __GNUC__
__extension__ typedef __float128 float128_type;
# else
typedef __float128 float128_type;
# endif
}}
#endif
#endif // BOOST_MP_STANDALONE
// Workarounds for numeric limits on old compilers
#ifdef BOOST_HAS_INT128
# ifndef INT128_MAX
# define INT128_MAX static_cast<boost::multiprecision::int128_type>((static_cast<boost::multiprecision::uint128_type>(1) << ((__SIZEOF_INT128__ * __CHAR_BIT__) - 1)) - 1)
# endif
# ifndef INT128_MIN
# define INT128_MIN (-INT128_MAX - 1)
# endif
# ifndef UINT128_MAX
# define UINT128_MAX ((2 * static_cast<boost::multiprecision::uint128_type>(INT128_MAX)) + 1)
# endif
#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
#endif // BOOST_MP_STANDALONE_CONFIG_HPP
+42
View File
@@ -0,0 +1,42 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2021 John Maddock.
// Copyright Christopher Kormanyos 2021. 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_MP_DETAIL_STATIC_ARRAY_HPP
#define BOOST_MP_DETAIL_STATIC_ARRAY_HPP
#include <array>
#include <cstddef>
#include <cstdint>
#include <initializer_list>
namespace boost { namespace multiprecision { namespace backends { namespace detail {
template <class ValueType, const std::uint32_t ElemNumber>
struct static_array : public std::array<ValueType, std::size_t(ElemNumber)>
{
private:
using base_class_type = std::array<ValueType, std::size_t(ElemNumber)>;
public:
static_array() noexcept
{
base_class_type::fill(typename base_class_type::value_type(0u));
}
static_array(std::initializer_list<std::uint32_t> lst) noexcept
{
std::copy(lst.begin(),
lst.begin() + (std::min)(std::size_t(lst.size()), std::size_t(ElemNumber)),
base_class_type::begin());
std::fill(base_class_type::begin() + (std::min)(std::size_t(lst.size()), std::size_t(ElemNumber)),
base_class_type::end(),
typename base_class_type::value_type(0u));
}
};
}}}} // namespace boost::multiprecision::backends::detail
#endif // BOOST_MP_DETAIL_STATIC_ARRAY_HPP
+48
View File
@@ -0,0 +1,48 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2023 John Maddock.
// Copyright Christopher Kormanyos 2013. 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_MP_DETAIL_STRING_HELPERS_HPP
#define BOOST_MP_DETAIL_STRING_HELPERS_HPP
#include <algorithm>
#include <cstring>
namespace boost { namespace multiprecision { namespace detail {
struct is_in_string
{
const char* begin;
const char* end;
is_in_string(const char* p) : begin(p), end(p + std::strlen(p)) {}
bool operator()(char s) { return std::find(begin, end, s) != end; }
};
struct is_not_in_string
{
const char* begin;
const char* end;
is_not_in_string(const char* p) : begin(p), end(p + std::strlen(p)) {}
bool operator()(char s) { return std::find(begin, end, s) == end; }
};
template <class Iterator>
std::size_t find_first_of(Iterator begin, Iterator end, const char* what)
{
return std::find_if(begin, end, is_in_string(what)) - begin;
}
template <class Iterator>
std::size_t find_first_not_of(Iterator begin, Iterator end, const char* what)
{
return std::find_if(begin, end, is_not_in_string(what)) - begin;
}
}}} // namespace boost::multiprecision::detail
#endif // BOOST_MP_DETAIL_STRING_HELPERS_HPP
+80
View File
@@ -0,0 +1,80 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2021 John Maddock.
// Copyright Christopher Kormanyos 2021. 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_MP_DETAIL_TABLES_HPP
#define BOOST_MP_DETAIL_TABLES_HPP
#include <algorithm>
#include <array>
#include <cstdint>
namespace boost { namespace multiprecision { namespace backends { namespace detail {
struct a029750
{
static constexpr std::uint32_t a029750_as_constexpr(const std::uint32_t value)
{
// Sloane's A029750 List of numbers of the form 2^k times 1, 3, 5 or 7.
// CoefficientList[Series[-(x + 1)^2 (x^2 + 1)^2/(2 x^4 - 1), {x, 0, 78}], x]
return ((value <= UINT32_C( 32)) ? UINT32_C( 32) : ((value <= UINT32_C( 40)) ? UINT32_C( 40) : ((value <= UINT32_C( 48)) ? UINT32_C( 48) : ((value <= UINT32_C( 56)) ? UINT32_C( 56) :
((value <= UINT32_C( 64)) ? UINT32_C( 64) : ((value <= UINT32_C( 80)) ? UINT32_C( 80) : ((value <= UINT32_C( 96)) ? UINT32_C( 96) : ((value <= UINT32_C( 112)) ? UINT32_C( 112) :
((value <= UINT32_C( 128)) ? UINT32_C( 128) : ((value <= UINT32_C( 160)) ? UINT32_C( 160) : ((value <= UINT32_C( 192)) ? UINT32_C( 192) : ((value <= UINT32_C( 224)) ? UINT32_C( 224) :
((value <= UINT32_C( 256)) ? UINT32_C( 256) : ((value <= UINT32_C( 320)) ? UINT32_C( 320) : ((value <= UINT32_C( 384)) ? UINT32_C( 384) : ((value <= UINT32_C( 448)) ? UINT32_C( 448) :
((value <= UINT32_C( 512)) ? UINT32_C( 512) : ((value <= UINT32_C( 640)) ? UINT32_C( 640) : ((value <= UINT32_C( 768)) ? UINT32_C( 768) : ((value <= UINT32_C( 896)) ? UINT32_C( 896) :
((value <= UINT32_C( 1024)) ? UINT32_C( 1024) : ((value <= UINT32_C( 1280)) ? UINT32_C( 1280) : ((value <= UINT32_C( 1536)) ? UINT32_C( 1536) : ((value <= UINT32_C( 1792)) ? UINT32_C( 1792) :
((value <= UINT32_C( 2048)) ? UINT32_C( 2048) : ((value <= UINT32_C( 2560)) ? UINT32_C( 2560) : ((value <= UINT32_C( 3072)) ? UINT32_C( 3072) : ((value <= UINT32_C( 3584)) ? UINT32_C( 3584) :
((value <= UINT32_C( 4096)) ? UINT32_C( 4096) : ((value <= UINT32_C( 5120)) ? UINT32_C( 5120) : ((value <= UINT32_C( 6144)) ? UINT32_C( 6144) : ((value <= UINT32_C( 7168)) ? UINT32_C( 7168) :
((value <= UINT32_C( 8192)) ? UINT32_C( 8192) : ((value <= UINT32_C( 10240)) ? UINT32_C( 10240) : ((value <= UINT32_C( 12288)) ? UINT32_C( 12288) : ((value <= UINT32_C( 14336)) ? UINT32_C( 14336) :
((value <= UINT32_C( 16384)) ? UINT32_C( 16384) : ((value <= UINT32_C( 20480)) ? UINT32_C( 20480) : ((value <= UINT32_C( 24576)) ? UINT32_C( 24576) : ((value <= UINT32_C( 28672)) ? UINT32_C( 28672) :
((value <= UINT32_C( 32768)) ? UINT32_C( 32768) : ((value <= UINT32_C( 40960)) ? UINT32_C( 40960) : ((value <= UINT32_C( 49152)) ? UINT32_C( 49152) : ((value <= UINT32_C( 57344)) ? UINT32_C( 57344) :
((value <= UINT32_C( 65536)) ? UINT32_C( 65536) : ((value <= UINT32_C( 81920)) ? UINT32_C( 81920) : ((value <= UINT32_C( 98304)) ? UINT32_C( 98304) : ((value <= UINT32_C( 114688)) ? UINT32_C( 114688) :
((value <= UINT32_C( 131072)) ? UINT32_C( 131072) : ((value <= UINT32_C( 163840)) ? UINT32_C( 163840) : ((value <= UINT32_C( 196608)) ? UINT32_C( 196608) : ((value <= UINT32_C( 229376)) ? UINT32_C( 229376) :
((value <= UINT32_C( 262144)) ? UINT32_C( 262144) : ((value <= UINT32_C( 327680)) ? UINT32_C( 327680) : ((value <= UINT32_C( 393216)) ? UINT32_C( 393216) : ((value <= UINT32_C( 458752)) ? UINT32_C( 458752) :
((value <= UINT32_C( 524288)) ? UINT32_C( 524288) : ((value <= UINT32_C( 655360)) ? UINT32_C( 655360) : ((value <= UINT32_C( 786432)) ? UINT32_C( 786432) : ((value <= UINT32_C( 917504)) ? UINT32_C( 917504) :
((value <= UINT32_C(1048576)) ? UINT32_C(1048576) : ((value <= UINT32_C(1310720)) ? UINT32_C(1310720) : ((value <= UINT32_C(1572864)) ? UINT32_C(1572864) : ((value <= UINT32_C(1835008)) ? UINT32_C(1835008) : UINT32_C(0x7FFFFFFF)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))));
}
static std::uint32_t a029750_as_runtime_value(const std::uint32_t value)
{
// Sloane's A029750 List of numbers of the form 2^k times 1, 3, 5 or 7.
// CoefficientList[Series[-(x + 1)^2 (x^2 + 1)^2/(2 x^4 - 1), {x, 0, 78}], x]
constexpr std::array<std::uint32_t, 65U> a029750_data =
{{
UINT32_C( 32), UINT32_C( 40), UINT32_C( 48), UINT32_C( 56),
UINT32_C( 64), UINT32_C( 80), UINT32_C( 96), UINT32_C( 112),
UINT32_C( 128), UINT32_C( 160), UINT32_C( 192), UINT32_C( 224),
UINT32_C( 256), UINT32_C( 320), UINT32_C( 384), UINT32_C( 448),
UINT32_C( 512), UINT32_C( 640), UINT32_C( 768), UINT32_C( 896),
UINT32_C( 1024), UINT32_C( 1280), UINT32_C( 1536), UINT32_C( 1792),
UINT32_C( 2048), UINT32_C( 2560), UINT32_C( 3072), UINT32_C( 3584),
UINT32_C( 4096), UINT32_C( 5120), UINT32_C( 6144), UINT32_C( 7168),
UINT32_C( 8192), UINT32_C( 10240), UINT32_C( 12288), UINT32_C( 14336),
UINT32_C( 16384), UINT32_C( 20480), UINT32_C( 24576), UINT32_C( 28672),
UINT32_C( 32768), UINT32_C( 40960), UINT32_C( 49152), UINT32_C( 57344),
UINT32_C( 65536), UINT32_C( 81920), UINT32_C( 98304), UINT32_C( 114688),
UINT32_C( 131072), UINT32_C( 163840), UINT32_C( 196608), UINT32_C( 229376),
UINT32_C( 262144), UINT32_C( 327680), UINT32_C( 393216), UINT32_C( 458752),
UINT32_C( 524288), UINT32_C( 655360), UINT32_C( 786432), UINT32_C( 917504),
UINT32_C( 1048576), UINT32_C(1310720), UINT32_C(1572864), UINT32_C(1835008),
UINT32_C(0x7FFFFFFF)
}};
const std::array<std::uint32_t, 65U>::const_iterator it =
std::lower_bound(a029750_data.cbegin(), a029750_data.cend(), value);
return ((it != a029750_data.cend()) ? *it : UINT32_C(0xFFFFFFFF));
}
};
constexpr std::uint32_t pow10_maker(std::uint32_t n)
{
// Make the constant power of 10^n.
return ((n == UINT32_C(0)) ? UINT32_C(1) : pow10_maker(n - UINT32_C(1)) * UINT32_C(10));
}
}}}} // namespace boost::multiprecision::backends::detail
#endif // BOOST_MP_DETAIL_TABLES_HPP
+75
View File
@@ -0,0 +1,75 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2013 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_MP_UBLAS_INTEROP_HPP
#define BOOST_MP_UBLAS_INTEROP_HPP
namespace boost { namespace numeric { namespace ublas {
template <class V>
class sparse_vector_element;
template <class V, class Backend, multiprecision::expression_template_option ExpressionTemplates>
inline bool operator==(const sparse_vector_element<V>& a, const ::boost::multiprecision::number<Backend, ExpressionTemplates>& b)
{
using ref_type = typename sparse_vector_element<V>::const_reference;
return static_cast<ref_type>(a) == b;
}
template <class X, class Y>
struct promote_traits;
template <class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1, class Backend2, boost::multiprecision::expression_template_option ExpressionTemplates2>
struct promote_traits<boost::multiprecision::number<Backend1, ExpressionTemplates1>, boost::multiprecision::number<Backend2, ExpressionTemplates2> >
{
using number1_t = boost::multiprecision::number<Backend1, ExpressionTemplates1>;
using number2_t = boost::multiprecision::number<Backend2, ExpressionTemplates2>;
using promote_type = typename std::conditional<
std::is_convertible<number1_t, number2_t>::value && !std::is_convertible<number2_t, number1_t>::value,
number2_t, number1_t>::type;
};
template <class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1, class Arithmetic>
struct promote_traits<boost::multiprecision::number<Backend1, ExpressionTemplates1>, Arithmetic>
{
using promote_type = boost::multiprecision::number<Backend1, ExpressionTemplates1>;
};
template <class Arithmetic, class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1>
struct promote_traits<Arithmetic, boost::multiprecision::number<Backend1, ExpressionTemplates1> >
{
using promote_type = boost::multiprecision::number<Backend1, ExpressionTemplates1>;
};
template <class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1, class tag, class Arg1, class Arg2, class Arg3, class Arg4>
struct promote_traits<boost::multiprecision::number<Backend1, ExpressionTemplates1>, boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> >
{
using number1_t = boost::multiprecision::number<Backend1, ExpressionTemplates1> ;
using expression_type = boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>;
using number2_t = typename expression_type::result_type ;
using promote_type = typename promote_traits<number1_t, number2_t>::promote_type ;
};
template <class tag, class Arg1, class Arg2, class Arg3, class Arg4, class Backend1, boost::multiprecision::expression_template_option ExpressionTemplates1>
struct promote_traits<boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, boost::multiprecision::number<Backend1, ExpressionTemplates1> >
{
using number1_t = boost::multiprecision::number<Backend1, ExpressionTemplates1> ;
using expression_type = boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>;
using number2_t = typename expression_type::result_type ;
using promote_type = typename promote_traits<number1_t, number2_t>::promote_type ;
};
template <class tag, class Arg1, class Arg2, class Arg3, class Arg4, class tagb, class Arg1b, class Arg2b, class Arg3b, class Arg4b>
struct promote_traits<boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>, boost::multiprecision::detail::expression<tagb, Arg1b, Arg2b, Arg3b, Arg4b> >
{
using expression1_t = boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4> ;
using number1_t = typename expression1_t::result_type ;
using expression2_t = boost::multiprecision::detail::expression<tagb, Arg1b, Arg2b, Arg3b, Arg4b>;
using number2_t = typename expression2_t::result_type ;
};
}}} // namespace boost::numeric::ublas
#endif
@@ -0,0 +1,212 @@
///////////////////////////////////////////////////////////////
// Copyright Jens Maurer 2000-2021
// Copyright Steven Watanabe 2011-2021
// Copyright John Maddock 2015-2021
// Copyright Matt Borland 2021
// 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
//
// This is a C++11 compliant port of Boost.Random's implementation
// of uniform_int_distribution. See their comments for detailed
// descriptions
#ifndef BOOST_MP_UNIFORM_INT_DISTRIBUTION_HPP
#define BOOST_MP_UNIFORM_INT_DISTRIBUTION_HPP
#include <limits>
#include <type_traits>
#include <boost/multiprecision/detail/standalone_config.hpp>
#include <boost/multiprecision/detail/assert.hpp>
#include <boost/multiprecision/traits/std_integer_traits.hpp>
namespace boost { namespace multiprecision {
namespace detail {
template <typename T, bool intrinsic>
struct make_unsigned_impl
{
using type = typename boost::multiprecision::detail::make_unsigned<T>::type;
};
template <typename T>
struct make_unsigned_impl<T, false>
{
using type = T;
};
template <typename T>
struct make_unsigned_mp
{
using type = typename make_unsigned_impl<T, boost::multiprecision::detail::is_integral<T>::value>::type;
};
template <typename Engine, typename T>
T generate_uniform_int (Engine& eng, T min_value, T max_value)
{
using range_type = typename boost::multiprecision::detail::make_unsigned_mp<T>::type;
using base_result = typename Engine::result_type;
using base_unsigned = typename boost::multiprecision::detail::make_unsigned_mp<base_result>::type;
const range_type range = max_value - min_value;
const base_result bmin = (eng.min)();
const base_unsigned brange = (eng.max)() - (eng.min)();
if(range == 0)
{
return min_value;
}
else if (brange < range)
{
for(;;)
{
range_type limit;
if(range == (std::numeric_limits<range_type>::max)())
{
limit = range / (range_type(brange) + 1);
if(range % (range_type(brange) + 1) == range_type(brange))
{
++limit;
}
}
else
{
limit = (range + 1) / (range_type(brange) + 1);
}
range_type result = 0;
range_type mult = 1;
while (mult <= limit)
{
result += static_cast<range_type>(static_cast<range_type>(eng() - bmin) * mult);
if(mult * range_type(brange) == range - mult + 1)
{
return(result);
}
mult *= range_type(brange)+range_type(1);
}
range_type result_increment = generate_uniform_int(eng, range_type(0), range_type(range/mult));
if(std::numeric_limits<range_type>::is_bounded && ((std::numeric_limits<range_type>::max)() / mult < result_increment))
{
continue;
}
result_increment *= mult;
result += result_increment;
if(result < result_increment)
{
continue;
}
if(result > range)
{
continue;
}
return result + min_value;
}
}
else
{
using mixed_range_type =
typename std::conditional<std::numeric_limits<range_type>::is_specialized && std::numeric_limits<base_unsigned>::is_specialized &&
(std::numeric_limits<range_type>::digits >= std::numeric_limits<base_unsigned>::digits),
range_type, base_unsigned>::type;
mixed_range_type bucket_size;
if(brange == (std::numeric_limits<base_unsigned>::max)())
{
bucket_size = static_cast<mixed_range_type>(brange) / (static_cast<mixed_range_type>(range)+1);
if(static_cast<mixed_range_type>(brange) % (static_cast<mixed_range_type>(range)+1) == static_cast<mixed_range_type>(range))
{
++bucket_size;
}
}
else
{
bucket_size = static_cast<mixed_range_type>(brange + 1) / (static_cast<mixed_range_type>(range)+1);
}
for(;;)
{
mixed_range_type result = eng() - bmin;
result /= bucket_size;
if(result <= static_cast<mixed_range_type>(range))
{
return result + min_value;
}
}
}
}
} // Namespace detail
template <typename Integer = int>
class uniform_int_distribution
{
private:
Integer min_;
Integer max_;
public:
class param_type
{
private:
Integer min_;
Integer max_;
public:
explicit param_type(Integer min_val, Integer max_val) : min_ {min_val}, max_ {max_val}
{
BOOST_MP_ASSERT(min_ <= max_);
}
Integer a() const { return min_; }
Integer b() const { return max_; }
};
explicit uniform_int_distribution(Integer min_arg, Integer max_arg) : min_ {min_arg}, max_ {max_arg}
{
BOOST_MP_ASSERT(min_ <= max_);
}
explicit uniform_int_distribution(const param_type& param_arg) : min_ {param_arg.a()}, max_ {param_arg.b()} {}
Integer min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return min_; }
Integer max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return max_; }
Integer a() const { return min_; }
Integer b() const { return max_; }
param_type param() const { return param_type(min_, max_); }
void param(const param_type& param_arg)
{
min_ = param_arg.a();
max_ = param_arg.b();
}
template <typename Engine>
Integer operator() (Engine& eng) const
{
return detail::generate_uniform_int(eng, min_, max_);
}
template <typename Engine>
Integer operator() (Engine& eng, const param_type& param_arg) const
{
return detail::generate_uniform_int(eng, param_arg.a(), param_arg.b());
}
};
}} // Namespaces
#endif // BOOST_MP_UNIFORM_INT_DISTRIBUTION_HPP
+374
View File
@@ -0,0 +1,374 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2012 John Maddock.
// Copyright Christopher Kormanyos 2013. 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_MP_UTYPE_HELPER_HPP
#define BOOST_MP_UTYPE_HELPER_HPP
#include <limits>
#include <cstdint>
namespace boost {
namespace multiprecision {
namespace detail {
template <const unsigned>
struct utype_helper
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<0U>
{
using exact = boost::uint8_t;
};
template <>
struct utype_helper<1U>
{
using exact = boost::uint8_t;
};
template <>
struct utype_helper<2U>
{
using exact = boost::uint8_t;
};
template <>
struct utype_helper<3U>
{
using exact = boost::uint8_t;
};
template <>
struct utype_helper<4U>
{
using exact = boost::uint8_t;
};
template <>
struct utype_helper<5U>
{
using exact = boost::uint8_t;
};
template <>
struct utype_helper<6U>
{
using exact = boost::uint8_t;
};
template <>
struct utype_helper<7U>
{
using exact = boost::uint8_t;
};
template <>
struct utype_helper<8U>
{
using exact = boost::uint8_t;
};
template <>
struct utype_helper<9U>
{
using exact = std::uint16_t;
};
template <>
struct utype_helper<10U>
{
using exact = std::uint16_t;
};
template <>
struct utype_helper<11U>
{
using exact = std::uint16_t;
};
template <>
struct utype_helper<12U>
{
using exact = std::uint16_t;
};
template <>
struct utype_helper<13U>
{
using exact = std::uint16_t;
};
template <>
struct utype_helper<14U>
{
using exact = std::uint16_t;
};
template <>
struct utype_helper<15U>
{
using exact = std::uint16_t;
};
template <>
struct utype_helper<16U>
{
using exact = std::uint16_t;
};
template <>
struct utype_helper<17U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<18U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<19U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<20U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<21U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<22U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<23U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<24U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<25U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<26U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<27U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<28U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<29U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<30U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<31U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<32U>
{
using exact = std::uint32_t;
};
template <>
struct utype_helper<33U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<34U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<35U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<36U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<37U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<38U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<39U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<40U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<41U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<42U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<43U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<44U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<45U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<46U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<47U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<48U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<49U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<50U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<51U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<52U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<53U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<54U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<55U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<56U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<57U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<58U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<59U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<60U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<61U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<62U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<63U>
{
using exact = std::uint64_t;
};
template <>
struct utype_helper<64U>
{
using exact = std::uint64_t;
};
template <class unsigned_type>
int utype_prior(unsigned_type ui)
{
// TBD: Implement a templated binary search for this.
int priority_bit;
unsigned_type priority_mask = unsigned_type(unsigned_type(1U) << (std::numeric_limits<unsigned_type>::digits - 1));
for (priority_bit = std::numeric_limits<unsigned_type>::digits - 1; priority_bit >= 0; --priority_bit)
{
if (unsigned_type(priority_mask & ui) != unsigned_type(0U))
{
break;
}
priority_mask >>= 1;
}
return priority_bit;
}
}}} // namespace boost::multiprecision::detail
#endif // BOOST_MP_UTYPE_HELPER_HPP