File indexing completed on 2025-01-18 09:42:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_MP_CPP_DEC_FLOAT_HPP
0017 #define BOOST_MP_CPP_DEC_FLOAT_HPP
0018
0019 #include <cmath>
0020 #include <cstdint>
0021 #include <cstdlib>
0022 #include <algorithm>
0023 #include <array>
0024 #include <initializer_list>
0025 #include <iomanip>
0026 #include <string>
0027 #include <limits>
0028 #include <stdexcept>
0029 #include <sstream>
0030 #include <locale>
0031 #include <ios>
0032 #include <boost/multiprecision/detail/standalone_config.hpp>
0033 #include <boost/multiprecision/number.hpp>
0034 #include <boost/multiprecision/detail/fpclassify.hpp>
0035 #include <boost/multiprecision/detail/dynamic_array.hpp>
0036 #include <boost/multiprecision/detail/hash.hpp>
0037 #include <boost/multiprecision/detail/float128_functions.hpp>
0038 #include <boost/multiprecision/detail/itos.hpp>
0039 #include <boost/multiprecision/detail/static_array.hpp>
0040 #include <boost/multiprecision/detail/tables.hpp>
0041 #include <boost/multiprecision/detail/no_exceptions_support.hpp>
0042 #include <boost/multiprecision/detail/assert.hpp>
0043
0044 #ifdef BOOST_MP_MATH_AVAILABLE
0045
0046
0047
0048 #include <boost/math/policies/policy.hpp>
0049
0050
0051
0052 #include <boost/math/special_functions/acosh.hpp>
0053 #include <boost/math/special_functions/asinh.hpp>
0054 #include <boost/math/special_functions/atanh.hpp>
0055 #include <boost/math/special_functions/cbrt.hpp>
0056 #include <boost/math/special_functions/expm1.hpp>
0057 #include <boost/math/special_functions/gamma.hpp>
0058 #endif
0059
0060 #ifdef BOOST_MSVC
0061 #pragma warning(push)
0062 #pragma warning(disable : 6326)
0063 #endif
0064
0065 namespace boost {
0066 namespace multiprecision {
0067
0068 template <unsigned Digits10, class ExponentType, class Allocator>
0069 struct number_category<backends::cpp_dec_float<Digits10, ExponentType, Allocator> > : public std::integral_constant<int, number_kind_floating_point>
0070 {};
0071
0072 namespace backends {
0073
0074 template <unsigned Digits10, class ExponentType, class Allocator>
0075 class cpp_dec_float
0076 {
0077 private:
0078
0079 static_assert(boost::multiprecision::detail::is_signed<ExponentType>::value,
0080 "ExponentType must be a signed built in integer type.");
0081
0082 static_assert(sizeof(ExponentType) > 1,
0083 "ExponentType is too small.");
0084
0085 static_assert(Digits10 < UINT32_C(0x80000000),
0086 "Digits10 exceeds the maximum.");
0087
0088
0089 static constexpr std::int32_t cpp_dec_float_digits10_limit_lo = INT32_C(9);
0090 static constexpr std::int32_t cpp_dec_float_digits10_limit_hi = static_cast<std::int32_t>((std::numeric_limits<std::int32_t>::max)() - 100);
0091
0092 static constexpr std::int32_t cpp_dec_float_elem_digits10 = INT32_C(8);
0093 static constexpr std::int32_t cpp_dec_float_elem_mask = INT32_C(100000000);
0094
0095 static constexpr std::int32_t cpp_dec_float_elems_for_kara = static_cast<std::int32_t>(128 + 1);
0096
0097 public:
0098 using signed_types = std::tuple<long long> ;
0099 using unsigned_types = std::tuple<unsigned long long>;
0100 using float_types = std::tuple<double, long double>;
0101 using exponent_type = ExponentType;
0102
0103
0104 static constexpr std::int32_t cpp_dec_float_radix = INT32_C(10);
0105 static constexpr std::int32_t cpp_dec_float_digits10 = ((static_cast<std::int32_t>(Digits10) < cpp_dec_float_digits10_limit_lo) ? cpp_dec_float_digits10_limit_lo : ((static_cast<std::int32_t>(Digits10) > cpp_dec_float_digits10_limit_hi) ? cpp_dec_float_digits10_limit_hi : static_cast<std::int32_t>(Digits10)));
0106 static constexpr exponent_type cpp_dec_float_max_exp10 = (static_cast<exponent_type>(1) << (std::numeric_limits<exponent_type>::digits - 5));
0107 static constexpr exponent_type cpp_dec_float_min_exp10 = -cpp_dec_float_max_exp10;
0108 static constexpr exponent_type cpp_dec_float_max_exp = cpp_dec_float_max_exp10;
0109 static constexpr exponent_type cpp_dec_float_min_exp = cpp_dec_float_min_exp10;
0110
0111 static_assert(cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp10 == -cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp10, "Failed exponent range check");
0112
0113 static_assert(0 == cpp_dec_float_max_exp10 % cpp_dec_float_elem_digits10, "Failed digit sanity check");
0114
0115 private:
0116
0117
0118
0119
0120 static constexpr std::int32_t cpp_dec_float_elem_number = static_cast<std::int32_t>(((Digits10 / cpp_dec_float_elem_digits10) + (((Digits10 % cpp_dec_float_elem_digits10) != 0) ? 1 : 0)) + 3);
0121
0122 public:
0123 static constexpr std::int32_t cpp_dec_float_max_digits10 = static_cast<std::int32_t>(cpp_dec_float_elem_number * cpp_dec_float_elem_digits10);
0124
0125 private:
0126 using array_type =
0127 typename std::conditional<std::is_void<Allocator>::value,
0128 detail::static_array <std::uint32_t, static_cast<std::uint32_t>(cpp_dec_float_elem_number)>,
0129 detail::dynamic_array<std::uint32_t, static_cast<std::uint32_t>(cpp_dec_float_elem_number), Allocator> >::type;
0130
0131 typedef enum enum_fpclass_type
0132 {
0133 cpp_dec_float_finite,
0134 cpp_dec_float_inf,
0135 cpp_dec_float_NaN
0136 } fpclass_type;
0137
0138 array_type data;
0139 exponent_type exp;
0140 bool neg;
0141 fpclass_type fpclass;
0142 std::int32_t prec_elem;
0143
0144
0145 explicit cpp_dec_float(fpclass_type c) : data(),
0146 exp(static_cast<exponent_type>(0)),
0147 neg(false),
0148 fpclass(c),
0149 prec_elem(cpp_dec_float_elem_number) {}
0150
0151
0152
0153 static cpp_dec_float from_lst(std::initializer_list<std::uint32_t> lst,
0154 const exponent_type e = 0,
0155 const bool n = false)
0156 {
0157 cpp_dec_float a;
0158
0159 a.data = array_type(lst);
0160 a.exp = e;
0161 a.neg = n;
0162 a.fpclass = cpp_dec_float_finite;
0163 a.prec_elem = cpp_dec_float_elem_number;
0164
0165 return a;
0166 }
0167
0168 public:
0169
0170 cpp_dec_float() noexcept(noexcept(array_type())) : data(),
0171 exp(static_cast<exponent_type>(0)),
0172 neg(false),
0173 fpclass(cpp_dec_float_finite),
0174 prec_elem(cpp_dec_float_elem_number) {}
0175
0176 cpp_dec_float(const char* s) : data(),
0177 exp(static_cast<exponent_type>(0)),
0178 neg(false),
0179 fpclass(cpp_dec_float_finite),
0180 prec_elem(cpp_dec_float_elem_number)
0181 {
0182 *this = s;
0183 }
0184
0185 template <class I>
0186 cpp_dec_float(I i,
0187 typename std::enable_if<boost::multiprecision::detail::is_unsigned<I>::value && (sizeof(I) <= sizeof(long long))>::type* = nullptr)
0188 : data(),
0189 exp(static_cast<exponent_type>(0)),
0190 neg(false),
0191 fpclass(cpp_dec_float_finite),
0192 prec_elem(cpp_dec_float_elem_number)
0193 {
0194 from_unsigned_long_long(i);
0195 }
0196
0197 template <class I>
0198 cpp_dec_float(I i,
0199 typename std::enable_if<( boost::multiprecision::detail::is_signed<I>::value
0200 && boost::multiprecision::detail::is_integral<I>::value
0201 && (sizeof(I) <= sizeof(long long)))>::type* = nullptr)
0202 : data(),
0203 exp(static_cast<exponent_type>(0)),
0204 neg(false),
0205 fpclass(cpp_dec_float_finite),
0206 prec_elem(cpp_dec_float_elem_number)
0207 {
0208 if (i < 0)
0209 {
0210 from_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(i));
0211 negate();
0212 }
0213 else
0214 from_unsigned_long_long(static_cast<unsigned long long>(i));
0215 }
0216
0217 cpp_dec_float(const cpp_dec_float& f) noexcept(noexcept(array_type(std::declval<const array_type&>())))
0218 : data(f.data),
0219 exp(f.exp),
0220 neg(f.neg),
0221 fpclass(f.fpclass),
0222 prec_elem(f.prec_elem) {}
0223
0224 template <unsigned D, class ET, class A>
0225 cpp_dec_float(const cpp_dec_float<D, ET, A>& f, typename std::enable_if<D <= Digits10>::type* = nullptr)
0226 : data(),
0227 exp(f.exp),
0228 neg(f.neg),
0229 fpclass(static_cast<fpclass_type>(static_cast<int>(f.fpclass))),
0230 prec_elem(cpp_dec_float_elem_number)
0231 {
0232 std::copy(f.data.begin(), f.data.begin() + f.prec_elem, data.begin());
0233 }
0234 template <unsigned D, class ET, class A>
0235 explicit cpp_dec_float(const cpp_dec_float<D, ET, A>& f, typename std::enable_if< !(D <= Digits10)>::type* = nullptr)
0236 : data(),
0237 exp(f.exp),
0238 neg(f.neg),
0239 fpclass(static_cast<fpclass_type>(static_cast<int>(f.fpclass))),
0240 prec_elem(cpp_dec_float_elem_number)
0241 {
0242
0243 std::copy(f.data.begin(), f.data.begin() + prec_elem, data.begin());
0244 }
0245
0246 template <class F>
0247 cpp_dec_float(const F val, typename std::enable_if<std::is_floating_point<F>::value
0248 >::type* = nullptr) : data(),
0249 exp(static_cast<exponent_type>(0)),
0250 neg(false),
0251 fpclass(cpp_dec_float_finite),
0252 prec_elem(cpp_dec_float_elem_number)
0253 {
0254 *this = val;
0255 }
0256
0257 cpp_dec_float(const double mantissa, const exponent_type exponent);
0258
0259 std::size_t hash() const
0260 {
0261 std::size_t result = 0;
0262 for (int i = 0; i < prec_elem; ++i)
0263 boost::multiprecision::detail::hash_combine(result, data[i]);
0264 boost::multiprecision::detail::hash_combine(result, exp, neg, static_cast<std::size_t>(fpclass));
0265 return result;
0266 }
0267
0268
0269 static const cpp_dec_float& nan () { static const cpp_dec_float val(cpp_dec_float_NaN); return val; }
0270 static const cpp_dec_float& inf () { static const cpp_dec_float val(cpp_dec_float_inf); return val; }
0271 static const cpp_dec_float& (max)() { static const cpp_dec_float val(from_lst({ std::uint32_t(1u) }, cpp_dec_float_max_exp10)); return val; }
0272 static const cpp_dec_float& (min)() { static const cpp_dec_float val(from_lst({ std::uint32_t(1u) }, cpp_dec_float_min_exp10)); return val; }
0273 static const cpp_dec_float& zero() { static const cpp_dec_float val(from_lst({ std::uint32_t(0u) })); return val; }
0274 static const cpp_dec_float& one () { static const cpp_dec_float val(from_lst({ std::uint32_t(1u) })); return val; }
0275 static const cpp_dec_float& two () { static const cpp_dec_float val(from_lst({ std::uint32_t(2u) })); return val; }
0276 static const cpp_dec_float& half() { static const cpp_dec_float val(from_lst({ std::uint32_t(cpp_dec_float_elem_mask / 2)}, -8)); return val; }
0277
0278 static const cpp_dec_float& double_min() { static const cpp_dec_float val((std::numeric_limits<double>::min)()); return val; }
0279 static const cpp_dec_float& double_max() { static const cpp_dec_float val((std::numeric_limits<double>::max)()); return val; }
0280
0281 static const cpp_dec_float& long_double_min()
0282 {
0283 #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0284 static const cpp_dec_float val(static_cast<long double>((std::numeric_limits<double>::min)()));
0285 #else
0286 static const cpp_dec_float val((std::numeric_limits<long double>::min)());
0287 #endif
0288 return val;
0289 }
0290
0291 static const cpp_dec_float& long_double_max()
0292 {
0293 #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0294 static const cpp_dec_float val(static_cast<long double>((std::numeric_limits<double>::max)()));
0295 #else
0296 static const cpp_dec_float val((std::numeric_limits<long double>::max)());
0297 #endif
0298 return val;
0299 }
0300
0301 static const cpp_dec_float& long_long_max () { static const cpp_dec_float val((std::numeric_limits<long long>::max)()); return val; }
0302 static const cpp_dec_float& long_long_min () { static const cpp_dec_float val((std::numeric_limits<long long>::min)()); return val; }
0303 static const cpp_dec_float& ulong_long_max() { static const cpp_dec_float val((std::numeric_limits<unsigned long long>::max)()); return val; }
0304
0305 static const cpp_dec_float& eps()
0306 {
0307 static const cpp_dec_float val
0308 (
0309 from_lst
0310 (
0311 {
0312 (std::uint32_t) detail::pow10_maker((std::uint32_t) ((std::int32_t) (INT32_C(1) + (std::int32_t) (((cpp_dec_float_digits10 / cpp_dec_float_elem_digits10) + ((cpp_dec_float_digits10 % cpp_dec_float_elem_digits10) != 0 ? 1 : 0)) * cpp_dec_float_elem_digits10)) - cpp_dec_float_digits10))
0313 },
0314 -(exponent_type) (((cpp_dec_float_digits10 / cpp_dec_float_elem_digits10) + ((cpp_dec_float_digits10 % cpp_dec_float_elem_digits10) != 0 ? 1 : 0)) * cpp_dec_float_elem_digits10)
0315 )
0316 );
0317
0318 return val;
0319 }
0320
0321
0322 cpp_dec_float& operator=(const cpp_dec_float& v) noexcept(noexcept(std::declval<array_type&>() = std::declval<const array_type&>()))
0323 {
0324 data = v.data;
0325 exp = v.exp;
0326 neg = v.neg;
0327 fpclass = v.fpclass;
0328 prec_elem = v.prec_elem;
0329 return *this;
0330 }
0331
0332 template <unsigned D>
0333 cpp_dec_float& operator=(const cpp_dec_float<D>& f)
0334 {
0335 exp = f.exp;
0336 neg = f.neg;
0337 fpclass = static_cast<enum_fpclass_type>(static_cast<int>(f.fpclass));
0338 unsigned elems = (std::min)(f.prec_elem, cpp_dec_float_elem_number);
0339 std::copy(f.data.begin(), f.data.begin() + elems, data.begin());
0340 std::fill(data.begin() + elems, data.end(), 0);
0341 prec_elem = cpp_dec_float_elem_number;
0342 return *this;
0343 }
0344
0345 cpp_dec_float& operator=(long long v)
0346 {
0347 if (v < 0)
0348 {
0349 from_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(v));
0350 negate();
0351 }
0352 else
0353 {
0354 using local_ulonglong_type = typename boost::multiprecision::detail::make_unsigned<long long>::type;
0355
0356 from_unsigned_long_long(static_cast<local_ulonglong_type>(v));
0357 }
0358 return *this;
0359 }
0360
0361 cpp_dec_float& operator=(unsigned long long v)
0362 {
0363 from_unsigned_long_long(v);
0364 return *this;
0365 }
0366 #ifdef BOOST_HAS_INT128
0367 cpp_dec_float& operator=(int128_type v)
0368 {
0369 *this = boost::multiprecision::detail::unsigned_abs(v);
0370 if (v < 0)
0371 negate();
0372 return *this;
0373 }
0374
0375 cpp_dec_float& operator=(uint128_type v)
0376 {
0377 using default_ops::eval_add;
0378 using default_ops::eval_multiply;
0379
0380 constexpr unsigned bit_shift = sizeof(unsigned long long) * CHAR_BIT;
0381 constexpr uint128_type mask = (static_cast<uint128_type>(1u) << bit_shift) - 1;
0382
0383 *this = static_cast<unsigned long long>(v & mask);
0384
0385 v >>= bit_shift;
0386
0387 while (v)
0388 {
0389 cpp_dec_float t(static_cast<unsigned long long>(v & mask));
0390 eval_multiply(t, cpp_dec_float::pow2(bit_shift));
0391 eval_add(*this, t);
0392 v >>= bit_shift;
0393 }
0394 return *this;
0395 }
0396 #endif
0397
0398 template <class Float>
0399 typename std::enable_if<std::is_floating_point<Float>::value, cpp_dec_float&>::type operator=(Float v);
0400
0401 cpp_dec_float& operator=(const char* v)
0402 {
0403 rd_string(v);
0404 return *this;
0405 }
0406
0407 cpp_dec_float& operator+=(const cpp_dec_float& v);
0408 cpp_dec_float& operator-=(const cpp_dec_float& v);
0409 cpp_dec_float& operator*=(const cpp_dec_float& v);
0410 cpp_dec_float& operator/=(const cpp_dec_float& v);
0411
0412 cpp_dec_float& add_unsigned_long_long(const unsigned long long n)
0413 {
0414 cpp_dec_float t;
0415 t.from_unsigned_long_long(n);
0416 return *this += t;
0417 }
0418
0419 cpp_dec_float& sub_unsigned_long_long(const unsigned long long n)
0420 {
0421 cpp_dec_float t;
0422 t.from_unsigned_long_long(n);
0423 return *this -= t;
0424 }
0425
0426 cpp_dec_float& mul_unsigned_long_long(const unsigned long long n);
0427 cpp_dec_float& div_unsigned_long_long(const unsigned long long n);
0428
0429
0430 cpp_dec_float& calculate_inv();
0431 cpp_dec_float& calculate_sqrt();
0432
0433 void negate()
0434 {
0435 if (!iszero())
0436 neg = !neg;
0437 }
0438
0439
0440 bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION() const { return (fpclass == cpp_dec_float_NaN); }
0441 bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION() const { return (fpclass == cpp_dec_float_inf); }
0442 bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION() const { return (fpclass == cpp_dec_float_finite); }
0443
0444 bool iszero() const
0445 {
0446 return ((fpclass == cpp_dec_float_finite) && (data[0u] == 0u));
0447 }
0448
0449 bool isone() const;
0450 bool isint() const;
0451 bool isneg() const { return neg; }
0452
0453
0454 cpp_dec_float& operator++()
0455 {
0456 return *this += one();
0457 }
0458
0459 cpp_dec_float& operator--()
0460 {
0461 return *this -= one();
0462 }
0463
0464 std::string str(std::intmax_t digits, std::ios_base::fmtflags f) const;
0465
0466 int compare(const cpp_dec_float& v) const;
0467
0468 template <class V>
0469 int compare(const V& v) const
0470 {
0471 cpp_dec_float<Digits10, ExponentType, Allocator> t;
0472 t = v;
0473 return compare(t);
0474 }
0475
0476 void swap(cpp_dec_float& v)
0477 {
0478 data.swap(v.data);
0479 std::swap(exp, v.exp);
0480 std::swap(neg, v.neg);
0481 std::swap(fpclass, v.fpclass);
0482 std::swap(prec_elem, v.prec_elem);
0483 }
0484
0485 double extract_double() const;
0486 long double extract_long_double() const;
0487 long long extract_signed_long_long() const;
0488 unsigned long long extract_unsigned_long_long() const;
0489 #ifdef BOOST_HAS_INT128
0490 int128_type extract_signed_int128() const;
0491 uint128_type extract_unsigned_int128() const;
0492 #endif
0493 void extract_parts(double& mantissa, exponent_type& exponent) const;
0494 cpp_dec_float extract_integer_part() const;
0495
0496 void precision(const std::int32_t prec_digits)
0497 {
0498 const std::int32_t elems =
0499 static_cast<std::int32_t>( static_cast<std::int32_t>(prec_digits / cpp_dec_float_elem_digits10)
0500 + (((prec_digits % cpp_dec_float_elem_digits10) != 0) ? 1 : 0));
0501
0502 prec_elem = (std::min)(cpp_dec_float_elem_number, (std::max)(elems, static_cast<std::int32_t>(2)));
0503 }
0504 static cpp_dec_float pow2(long long i);
0505 exponent_type order() const
0506 {
0507 const bool bo_order_is_zero = ((!(isfinite)()) || (data[0] == static_cast<std::uint32_t>(0u)));
0508
0509
0510
0511 exponent_type prefix = 0;
0512
0513 if (data[0] >= 100000UL)
0514 {
0515 if (data[0] >= 10000000UL)
0516 {
0517 if (data[0] >= 100000000UL)
0518 {
0519 if (data[0] >= 1000000000UL)
0520 prefix = 9;
0521 else
0522 prefix = 8;
0523 }
0524 else
0525 prefix = 7;
0526 }
0527 else
0528 {
0529 if (data[0] >= 1000000UL)
0530 prefix = 6;
0531 else
0532 prefix = 5;
0533 }
0534 }
0535 else
0536 {
0537 if (data[0] >= 1000UL)
0538 {
0539 if (data[0] >= 10000UL)
0540 prefix = 4;
0541 else
0542 prefix = 3;
0543 }
0544 else
0545 {
0546 if (data[0] >= 100)
0547 prefix = 2;
0548 else if (data[0] >= 10)
0549 prefix = 1;
0550 }
0551 }
0552
0553 return (bo_order_is_zero ? static_cast<exponent_type>(0) : static_cast<exponent_type>(exp + prefix));
0554 }
0555
0556 #ifndef BOOST_MP_STANDALONE
0557 template <class Archive>
0558 void serialize(Archive& ar, const unsigned int )
0559 {
0560 for (unsigned i = 0; i < data.size(); ++i)
0561 ar& boost::make_nvp("digit", data[i]);
0562 ar& boost::make_nvp("exponent", exp);
0563 ar& boost::make_nvp("sign", neg);
0564 ar& boost::make_nvp("class-type", fpclass);
0565 ar& boost::make_nvp("precision", prec_elem);
0566 }
0567 #endif
0568
0569 private:
0570 static bool data_elem_is_non_zero_predicate(const std::uint32_t& d) { return (d != static_cast<std::uint32_t>(0u)); }
0571 static bool data_elem_is_non_nine_predicate(const std::uint32_t& d) { return (d != static_cast<std::uint32_t>(cpp_dec_float::cpp_dec_float_elem_mask - 1)); }
0572 static bool char_is_nonzero_predicate(const char& c) { return (c != static_cast<char>('0')); }
0573
0574 void from_unsigned_long_long(const unsigned long long u);
0575
0576 template <typename InputIteratorTypeLeft,
0577 typename InputIteratorTypeRight>
0578 static int compare_ranges(InputIteratorTypeLeft a,
0579 InputIteratorTypeRight b,
0580 const std::uint32_t count = cpp_dec_float_elem_number);
0581
0582 static std::uint32_t eval_add_n( std::uint32_t* r,
0583 const std::uint32_t* u,
0584 const std::uint32_t* v,
0585 const std::int32_t count);
0586
0587 static std::uint32_t eval_subtract_n( std::uint32_t* r,
0588 const std::uint32_t* u,
0589 const std::uint32_t* v,
0590 const std::int32_t count);
0591
0592 static void eval_multiply_n_by_n_to_2n( std::uint32_t* r,
0593 const std::uint32_t* a,
0594 const std::uint32_t* b,
0595 const std::uint32_t count);
0596
0597 static std::uint32_t mul_loop_n(std::uint32_t* const u, std::uint32_t n, const std::int32_t p);
0598 static std::uint32_t div_loop_n(std::uint32_t* const u, std::uint32_t n, const std::int32_t p);
0599
0600 static void eval_multiply_kara_propagate_carry (std::uint32_t* t, const std::uint32_t n, const std::uint32_t carry);
0601 static void eval_multiply_kara_propagate_borrow(std::uint32_t* t, const std::uint32_t n, const bool has_borrow);
0602 static void eval_multiply_kara_n_by_n_to_2n ( std::uint32_t* r,
0603 const std::uint32_t* a,
0604 const std::uint32_t* b,
0605 const std::uint32_t n,
0606 std::uint32_t* t);
0607
0608 template<unsigned D>
0609 void eval_mul_dispatch_multiplication_method(
0610 const cpp_dec_float<D, ExponentType, Allocator>& v,
0611 const std::int32_t prec_elems_for_multiply,
0612 const typename std::enable_if< (D == Digits10)
0613 && (cpp_dec_float<D, ExponentType, Allocator>::cpp_dec_float_elem_number < cpp_dec_float_elems_for_kara)>::type* = nullptr)
0614 {
0615
0616
0617 using array_for_mul_result_type =
0618 typename std::conditional<std::is_void<Allocator>::value,
0619 detail::static_array <std::uint32_t, std::uint32_t(cpp_dec_float_elem_number * 2)>,
0620 detail::dynamic_array<std::uint32_t, std::uint32_t(cpp_dec_float_elem_number * 2), Allocator> >::type;
0621
0622 array_for_mul_result_type result;
0623
0624 eval_multiply_n_by_n_to_2n(result.data(), data.data(), v.data.data(), static_cast<std::uint32_t>(prec_elems_for_multiply));
0625
0626
0627 if(result[0U] != static_cast<std::uint32_t>(0U))
0628 {
0629 exp += static_cast<exponent_type>(cpp_dec_float_elem_digits10);
0630
0631
0632 std::copy(result.cbegin(),
0633 result.cbegin() + static_cast<std::ptrdiff_t>(prec_elems_for_multiply),
0634 data.begin());
0635 }
0636 else
0637 {
0638 std::copy(result.cbegin() + 1,
0639 result.cbegin() + (std::min)(static_cast<std::int32_t>(prec_elems_for_multiply + 1), cpp_dec_float_elem_number),
0640 data.begin());
0641 }
0642 }
0643
0644 template<unsigned D>
0645 void eval_mul_dispatch_multiplication_method(
0646 const cpp_dec_float<D, ExponentType, Allocator>& v,
0647 const std::int32_t prec_elems_for_multiply,
0648 const typename std::enable_if< (D == Digits10)
0649 && !(cpp_dec_float<D, ExponentType, Allocator>::cpp_dec_float_elem_number < cpp_dec_float_elems_for_kara)>::type* = nullptr)
0650 {
0651 if(prec_elems_for_multiply < cpp_dec_float_elems_for_kara)
0652 {
0653
0654
0655 using array_for_mul_result_type =
0656 typename std::conditional<std::is_void<Allocator>::value,
0657 detail::static_array <std::uint32_t, std::uint32_t(cpp_dec_float_elem_number * 2)>,
0658 detail::dynamic_array<std::uint32_t, std::uint32_t(cpp_dec_float_elem_number * 2), Allocator> >::type;
0659
0660 array_for_mul_result_type result;
0661
0662 eval_multiply_n_by_n_to_2n(result.data(), data.data(), v.data.data(), static_cast<std::uint32_t>(prec_elems_for_multiply));
0663
0664
0665 if(result[0U] != static_cast<std::uint32_t>(0U))
0666 {
0667 exp += static_cast<exponent_type>(cpp_dec_float_elem_digits10);
0668
0669
0670 std::copy(result.cbegin(),
0671 result.cbegin() + static_cast<std::ptrdiff_t>(prec_elems_for_multiply),
0672 data.begin());
0673 }
0674 else
0675 {
0676 std::copy(result.cbegin() + 1,
0677 result.cbegin() + (std::min)(static_cast<std::int32_t>(prec_elems_for_multiply + 1), cpp_dec_float_elem_number),
0678 data.begin());
0679 }
0680 }
0681 else
0682 {
0683
0684
0685 using array_for_kara_tmp_type =
0686 typename std::conditional<std::is_void<Allocator>::value,
0687 detail::static_array <std::uint32_t, detail::a029750::a029750_as_constexpr(static_cast<std::uint32_t>(cpp_dec_float_elem_number)) * 8U>,
0688 detail::dynamic_array<std::uint32_t, detail::a029750::a029750_as_constexpr(static_cast<std::uint32_t>(cpp_dec_float_elem_number)) * 8U, Allocator> >::type;
0689
0690
0691 const std::uint32_t kara_elems_for_multiply =
0692 detail::a029750::a029750_as_runtime_value(static_cast<std::uint32_t>(prec_elems_for_multiply));
0693
0694 array_for_kara_tmp_type my_kara_mul_pool;
0695
0696 std::uint32_t* result = my_kara_mul_pool.data() + (kara_elems_for_multiply * 0U);
0697 std::uint32_t* t = my_kara_mul_pool.data() + (kara_elems_for_multiply * 2U);
0698 std::uint32_t* u_local = my_kara_mul_pool.data() + (kara_elems_for_multiply * 6U);
0699 std::uint32_t* v_local = my_kara_mul_pool.data() + (kara_elems_for_multiply * 7U);
0700
0701 std::copy( data.cbegin(), data.cbegin() + prec_elems_for_multiply, u_local);
0702 std::copy(v.data.cbegin(), v.data.cbegin() + prec_elems_for_multiply, v_local);
0703
0704 eval_multiply_kara_n_by_n_to_2n(result,
0705 u_local,
0706 v_local,
0707 kara_elems_for_multiply,
0708 t);
0709
0710
0711 if(result[0U] != static_cast<std::uint32_t>(0U))
0712 {
0713 exp += static_cast<exponent_type>(cpp_dec_float_elem_digits10);
0714
0715
0716 std::copy(result,
0717 result + static_cast<std::ptrdiff_t>(prec_elems_for_multiply),
0718 data.begin());
0719 }
0720 else
0721 {
0722 std::copy(result + 1,
0723 result + (std::min)(static_cast<std::int32_t>(prec_elems_for_multiply + 1), cpp_dec_float_elem_number),
0724 data.begin());
0725 }
0726 }
0727 }
0728
0729 bool rd_string(const char* const s);
0730
0731 template <unsigned D, class ET, class A>
0732 friend class cpp_dec_float;
0733 };
0734
0735 template <unsigned Digits10, class ExponentType, class Allocator>
0736 constexpr std::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_radix;
0737 template <unsigned Digits10, class ExponentType, class Allocator>
0738 constexpr std::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10_limit_lo;
0739 template <unsigned Digits10, class ExponentType, class Allocator>
0740 constexpr std::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10_limit_hi;
0741 template <unsigned Digits10, class ExponentType, class Allocator>
0742 constexpr std::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10;
0743 template <unsigned Digits10, class ExponentType, class Allocator>
0744 constexpr ExponentType cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp;
0745 template <unsigned Digits10, class ExponentType, class Allocator>
0746 constexpr ExponentType cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp;
0747 template <unsigned Digits10, class ExponentType, class Allocator>
0748 constexpr ExponentType cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp10;
0749 template <unsigned Digits10, class ExponentType, class Allocator>
0750 constexpr ExponentType cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp10;
0751 template <unsigned Digits10, class ExponentType, class Allocator>
0752 constexpr std::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_elem_digits10;
0753 template <unsigned Digits10, class ExponentType, class Allocator>
0754 constexpr std::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_elem_number;
0755 template <unsigned Digits10, class ExponentType, class Allocator>
0756 constexpr std::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_elem_mask;
0757
0758 template <unsigned Digits10, class ExponentType, class Allocator>
0759 cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::operator+=(const cpp_dec_float<Digits10, ExponentType, Allocator>& v)
0760 {
0761 if ((isnan)())
0762 {
0763 return *this;
0764 }
0765
0766 if ((isinf)())
0767 {
0768 if ((v.isinf)() && (isneg() != v.isneg()))
0769 {
0770 *this = nan();
0771 }
0772 return *this;
0773 }
0774
0775 if (iszero())
0776 {
0777 return operator=(v);
0778 }
0779
0780 if ((v.isnan)() || (v.isinf)())
0781 {
0782 *this = v;
0783 return *this;
0784 }
0785
0786
0787 constexpr exponent_type max_delta_exp =
0788 static_cast<exponent_type>((cpp_dec_float_elem_number - 1) * cpp_dec_float_elem_digits10);
0789
0790 const exponent_type ofs_exp = static_cast<exponent_type>(exp - v.exp);
0791
0792
0793 if (v.iszero() || (ofs_exp > max_delta_exp))
0794 {
0795
0796 return *this;
0797 }
0798 else if (ofs_exp < -max_delta_exp)
0799 {
0800
0801 return operator=(v);
0802 }
0803
0804
0805
0806 typename array_type::pointer p_u = data.data();
0807 typename array_type::const_pointer p_v = v.data.data();
0808 bool b_copy = false;
0809 const std::int32_t ofs = static_cast<std::int32_t>(static_cast<std::int32_t>(ofs_exp) / cpp_dec_float_elem_digits10);
0810 array_type n_data;
0811
0812 if (neg == v.neg)
0813 {
0814
0815
0816
0817
0818 if (ofs >= static_cast<std::int32_t>(0))
0819 {
0820 std::copy(v.data.cbegin(), v.data.cend() - static_cast<std::ptrdiff_t>(ofs), n_data.begin() + static_cast<std::ptrdiff_t>(ofs));
0821 std::fill(n_data.begin(), n_data.begin() + static_cast<std::ptrdiff_t>(ofs), static_cast<std::uint32_t>(0u));
0822 p_v = n_data.data();
0823 }
0824 else
0825 {
0826 std::copy(data.cbegin(), data.cend() - static_cast<std::ptrdiff_t>(-ofs), n_data.begin() + static_cast<std::ptrdiff_t>(-ofs));
0827 std::fill(n_data.begin(), n_data.begin() + static_cast<std::ptrdiff_t>(-ofs), static_cast<std::uint32_t>(0u));
0828 p_u = n_data.data();
0829 b_copy = true;
0830 }
0831
0832
0833 const std::uint32_t carry = eval_add_n(p_u, p_u, p_v, cpp_dec_float_elem_number);
0834
0835 if (b_copy)
0836 {
0837 data = n_data;
0838 exp = v.exp;
0839 }
0840
0841
0842 if (carry != static_cast<std::uint32_t>(0u))
0843 {
0844 std::copy_backward(data.cbegin(), data.cend() - static_cast<std::size_t>(1u), data.end());
0845 data[0] = carry;
0846 exp += static_cast<exponent_type>(cpp_dec_float_elem_digits10);
0847 }
0848 }
0849 else
0850 {
0851
0852
0853 if ((ofs > static_cast<std::int32_t>(0)) || ((ofs == static_cast<std::int32_t>(0)) && (compare_ranges(data.cbegin(), v.data.cbegin()) > static_cast<std::int32_t>(0))))
0854 {
0855
0856
0857
0858
0859 std::copy(v.data.cbegin(), v.data.cend() - static_cast<std::ptrdiff_t>(ofs), n_data.begin() + static_cast<std::ptrdiff_t>(ofs));
0860 std::fill(n_data.begin(), n_data.begin() + static_cast<std::ptrdiff_t>(ofs), static_cast<std::uint32_t>(0u));
0861 p_v = n_data.data();
0862 }
0863 else
0864 {
0865 if (ofs != static_cast<std::int32_t>(0))
0866 {
0867
0868
0869 std::copy_backward(data.cbegin(), data.cend() - static_cast<std::ptrdiff_t>(-ofs), data.end());
0870 std::fill(data.begin(), data.begin() + static_cast<std::ptrdiff_t>(-ofs), static_cast<std::uint32_t>(0u));
0871 }
0872
0873
0874
0875
0876
0877 n_data = v.data;
0878 p_u = n_data.data();
0879 p_v = data.data();
0880 b_copy = true;
0881 }
0882
0883
0884 static_cast<void>(eval_subtract_n(p_u, p_u, p_v, cpp_dec_float_elem_number));
0885
0886 if (b_copy)
0887 {
0888 data = n_data;
0889 exp = v.exp;
0890 neg = v.neg;
0891 }
0892
0893
0894 const typename array_type::const_iterator first_nonzero_elem = std::find_if(data.begin(), data.end(), data_elem_is_non_zero_predicate);
0895
0896 if (first_nonzero_elem != data.begin())
0897 {
0898 if (first_nonzero_elem == data.end())
0899 {
0900
0901
0902 neg = false;
0903 exp = static_cast<exponent_type>(0);
0904 }
0905 else
0906 {
0907
0908 const std::size_t sj = static_cast<std::size_t>(std::distance<typename array_type::const_iterator>(data.begin(), first_nonzero_elem));
0909
0910 std::copy(data.begin() + static_cast<std::ptrdiff_t>(sj), data.end(), data.begin());
0911 std::fill(data.end() - static_cast<std::ptrdiff_t>(sj), data.end(), static_cast<std::uint32_t>(0u));
0912
0913 exp -= static_cast<exponent_type>(sj * static_cast<std::size_t>(cpp_dec_float_elem_digits10));
0914 }
0915 }
0916 }
0917
0918
0919 if (iszero())
0920 return (*this = zero());
0921
0922
0923 const bool b_result_might_overflow = (exp >= static_cast<exponent_type>(cpp_dec_float_max_exp10));
0924
0925
0926 if (b_result_might_overflow)
0927 {
0928 const bool b_result_is_neg = neg;
0929 neg = false;
0930
0931 if (compare((cpp_dec_float::max)()) > 0)
0932 *this = inf();
0933
0934 neg = b_result_is_neg;
0935 }
0936
0937 return *this;
0938 }
0939
0940 template <unsigned Digits10, class ExponentType, class Allocator>
0941 cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::operator-=(const cpp_dec_float<Digits10, ExponentType, Allocator>& v)
0942 {
0943
0944 negate();
0945 *this += v;
0946 negate();
0947 return *this;
0948 }
0949
0950 template <unsigned Digits10, class ExponentType, class Allocator>
0951 cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::operator*=(const cpp_dec_float<Digits10, ExponentType, Allocator>& v)
0952 {
0953
0954 const bool b_result_is_neg = (neg != v.neg);
0955
0956
0957 neg = false;
0958
0959
0960 const bool b_u_is_inf = (isinf)();
0961 const bool b_v_is_inf = (v.isinf)();
0962 const bool b_u_is_zero = iszero();
0963 const bool b_v_is_zero = v.iszero();
0964
0965 if (((isnan)() || (v.isnan)()) || (b_u_is_inf && b_v_is_zero) || (b_v_is_inf && b_u_is_zero))
0966 {
0967 *this = nan();
0968 return *this;
0969 }
0970
0971 if (b_u_is_inf || b_v_is_inf)
0972 {
0973 *this = inf();
0974 if (b_result_is_neg)
0975 negate();
0976 return *this;
0977 }
0978
0979 if (b_u_is_zero || b_v_is_zero)
0980 {
0981 return *this = zero();
0982 }
0983
0984
0985 const bool b_result_might_overflow = ((exp + v.exp) >= static_cast<exponent_type>(cpp_dec_float_max_exp10));
0986 const bool b_result_might_underflow = ((exp + v.exp) <= static_cast<exponent_type>(cpp_dec_float_min_exp10));
0987
0988
0989 exp += v.exp;
0990
0991 const std::int32_t prec_mul = (std::min)(prec_elem, v.prec_elem);
0992
0993 eval_mul_dispatch_multiplication_method(v, prec_mul);
0994
0995
0996 if (b_result_might_overflow && (compare((cpp_dec_float::max)()) > 0))
0997 {
0998 *this = inf();
0999 }
1000
1001
1002 if (b_result_might_underflow && (compare((cpp_dec_float::min)()) < 0))
1003 {
1004 *this = zero();
1005
1006 return *this;
1007 }
1008
1009
1010 neg = b_result_is_neg;
1011
1012 return *this;
1013 }
1014
1015 template <unsigned Digits10, class ExponentType, class Allocator>
1016 cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::operator/=(const cpp_dec_float<Digits10, ExponentType, Allocator>& v)
1017 {
1018 if (iszero())
1019 {
1020 if ((v.isnan)())
1021 {
1022 return *this = v;
1023 }
1024 else if (v.iszero())
1025 {
1026 return *this = nan();
1027 }
1028 }
1029
1030 const bool u_and_v_are_finite_and_identical = ((isfinite)() && (fpclass == v.fpclass) && (exp == v.exp) && (compare_ranges(data.cbegin(), v.data.cbegin()) == static_cast<std::int32_t>(0)));
1031
1032 if (u_and_v_are_finite_and_identical)
1033 {
1034 if (neg != v.neg)
1035 {
1036 *this = one();
1037 negate();
1038 }
1039 else
1040 *this = one();
1041 return *this;
1042 }
1043 else
1044 {
1045 cpp_dec_float t(v);
1046 t.calculate_inv();
1047 return operator*=(t);
1048 }
1049 }
1050
1051 template <unsigned Digits10, class ExponentType, class Allocator>
1052 cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::mul_unsigned_long_long(const unsigned long long n)
1053 {
1054
1055
1056
1057 const bool b_neg = neg;
1058
1059
1060 neg = false;
1061
1062
1063 const bool b_u_is_inf = (isinf)();
1064 const bool b_n_is_zero = (n == static_cast<std::int32_t>(0));
1065
1066 if ((isnan)() || (b_u_is_inf && b_n_is_zero))
1067 {
1068 return (*this = nan());
1069 }
1070
1071 if (b_u_is_inf)
1072 {
1073 *this = inf();
1074 if (b_neg)
1075 negate();
1076 return *this;
1077 }
1078
1079 if (iszero() || b_n_is_zero)
1080 {
1081
1082 return *this = zero();
1083 }
1084
1085 if (n >= static_cast<unsigned long long>(cpp_dec_float_elem_mask))
1086 {
1087 neg = b_neg;
1088 cpp_dec_float t;
1089 t = n;
1090 return operator*=(t);
1091 }
1092
1093 if (n == static_cast<unsigned long long>(1u))
1094 {
1095 neg = b_neg;
1096 return *this;
1097 }
1098
1099
1100 const std::uint32_t nn = static_cast<std::uint32_t>(n);
1101 const std::uint32_t carry = mul_loop_n(data.data(), nn, prec_elem);
1102
1103
1104 if (carry != static_cast<std::uint32_t>(0u))
1105 {
1106 exp += static_cast<exponent_type>(cpp_dec_float_elem_digits10);
1107
1108
1109 std::copy_backward(data.begin(),
1110 data.begin() + static_cast<std::ptrdiff_t>(prec_elem - static_cast<std::int32_t>(1)),
1111 data.begin() + static_cast<std::ptrdiff_t>(prec_elem));
1112
1113 data.front() = static_cast<std::uint32_t>(carry);
1114 }
1115
1116
1117 const bool b_result_might_overflow = (exp >= cpp_dec_float_max_exp10);
1118
1119
1120 if (b_result_might_overflow && (compare((cpp_dec_float::max)()) > 0))
1121 {
1122 *this = inf();
1123 }
1124
1125
1126 neg = b_neg;
1127
1128 return *this;
1129 }
1130
1131 template <unsigned Digits10, class ExponentType, class Allocator>
1132 cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::div_unsigned_long_long(const unsigned long long n)
1133 {
1134
1135
1136
1137 const bool b_neg = neg;
1138
1139
1140 neg = false;
1141
1142
1143 if ((isnan)())
1144 {
1145 return *this;
1146 }
1147
1148 if ((isinf)())
1149 {
1150 *this = inf();
1151 if (b_neg)
1152 negate();
1153 return *this;
1154 }
1155
1156 if (n == static_cast<unsigned long long>(0u))
1157 {
1158
1159 if (iszero())
1160 {
1161 *this = nan();
1162 return *this;
1163 }
1164 else
1165 {
1166 *this = inf();
1167 if (isneg())
1168 negate();
1169 return *this;
1170 }
1171 }
1172
1173 if (iszero())
1174 {
1175 return *this;
1176 }
1177
1178 if (n >= static_cast<unsigned long long>(cpp_dec_float_elem_mask))
1179 {
1180 neg = b_neg;
1181 cpp_dec_float t;
1182 t = n;
1183 return operator/=(t);
1184 }
1185
1186 const std::uint32_t nn = static_cast<std::uint32_t>(n);
1187
1188 if (nn > static_cast<std::uint32_t>(1u))
1189 {
1190
1191 const std::uint32_t prev = div_loop_n(data.data(), nn, prec_elem);
1192
1193
1194 if (data[0] == static_cast<std::uint32_t>(0u))
1195 {
1196
1197 exp -= static_cast<exponent_type>(cpp_dec_float_elem_digits10);
1198
1199
1200 std::copy(data.begin() + static_cast<std::ptrdiff_t>(1),
1201 data.begin() + static_cast<std::ptrdiff_t>(prec_elem - static_cast<std::int32_t>(1)),
1202 data.begin());
1203
1204 data[static_cast<std::size_t>(prec_elem - static_cast<std::int32_t>(1))] = static_cast<std::uint32_t>(static_cast<std::uint64_t>(prev * static_cast<std::uint64_t>(cpp_dec_float_elem_mask)) / nn);
1205 }
1206 }
1207
1208
1209 const bool b_result_might_underflow = (exp <= cpp_dec_float_min_exp10);
1210
1211
1212 if (b_result_might_underflow && (compare((cpp_dec_float::min)()) < 0))
1213 return (*this = zero());
1214
1215
1216 neg = b_neg;
1217
1218 return *this;
1219 }
1220
1221 template <unsigned Digits10, class ExponentType, class Allocator>
1222 cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::calculate_inv()
1223 {
1224
1225 const bool b_neg = neg;
1226
1227 neg = false;
1228
1229
1230 if (iszero())
1231 {
1232 *this = inf();
1233 if (b_neg)
1234 negate();
1235 return *this;
1236 }
1237
1238 if ((isnan)())
1239 {
1240 return *this;
1241 }
1242
1243 if ((isinf)())
1244 {
1245 return *this = zero();
1246 }
1247
1248 if (isone())
1249 {
1250 if (b_neg)
1251 negate();
1252 return *this;
1253 }
1254
1255
1256 cpp_dec_float<Digits10, ExponentType, Allocator> x(*this);
1257
1258
1259
1260
1261 double dd;
1262 exponent_type ne;
1263 x.extract_parts(dd, ne);
1264
1265
1266 operator=(cpp_dec_float<Digits10, ExponentType, Allocator>(1.0 / dd, -ne));
1267
1268
1269
1270
1271
1272 constexpr std::int32_t double_digits10_minus_a_few = std::numeric_limits<double>::digits10 - 3;
1273
1274 for (std::int32_t digits = double_digits10_minus_a_few; digits <= cpp_dec_float_max_digits10; digits *= static_cast<std::int32_t>(2))
1275 {
1276
1277 precision(static_cast<std::int32_t>((digits + 10) * static_cast<std::int32_t>(2)));
1278 x.precision(static_cast<std::int32_t>((digits + 10) * static_cast<std::int32_t>(2)));
1279
1280
1281 cpp_dec_float t(*this);
1282 t *= x;
1283 t -= two();
1284 t.negate();
1285 *this *= t;
1286 }
1287
1288 neg = b_neg;
1289
1290 prec_elem = cpp_dec_float_elem_number;
1291
1292 return *this;
1293 }
1294
1295 template <unsigned Digits10, class ExponentType, class Allocator>
1296 cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::calculate_sqrt()
1297 {
1298
1299
1300 if ((isinf)() && !isneg())
1301 {
1302 return *this;
1303 }
1304
1305 if (isneg() || (!(isfinite)()))
1306 {
1307 *this = nan();
1308 errno = EDOM;
1309 return *this;
1310 }
1311
1312 if (iszero() || isone())
1313 {
1314 return *this;
1315 }
1316
1317
1318 cpp_dec_float<Digits10, ExponentType, Allocator> x(*this);
1319
1320
1321
1322
1323 double dd;
1324 exponent_type ne;
1325 extract_parts(dd, ne);
1326
1327
1328 if ((ne % static_cast<exponent_type>(2)) != static_cast<exponent_type>(0))
1329 {
1330 ++ne;
1331 dd /= 10.0;
1332 }
1333
1334
1335
1336 const double sqd = std::sqrt(dd);
1337
1338 *this = cpp_dec_float<Digits10, ExponentType, Allocator>(sqd, static_cast<ExponentType>(ne / static_cast<ExponentType>(2)));
1339
1340
1341 cpp_dec_float<Digits10, ExponentType, Allocator> vi(0.5 / sqd, static_cast<ExponentType>(-ne / static_cast<ExponentType>(2)));
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352 constexpr std::uint32_t double_digits10_minus_a_few = std::numeric_limits<double>::digits10 - 3;
1353
1354 for (std::int32_t digits = double_digits10_minus_a_few; digits <= cpp_dec_float_max_digits10; digits *= 2)
1355 {
1356
1357 precision((digits + 10) * 2);
1358 vi.precision((digits + 10) * 2);
1359
1360
1361 cpp_dec_float t(*this);
1362 t *= vi;
1363 t.negate();
1364 t.mul_unsigned_long_long(2u);
1365 t += one();
1366 t *= vi;
1367 vi += t;
1368
1369
1370 t = *this;
1371 t *= *this;
1372 t.negate();
1373 t += x;
1374 t *= vi;
1375 *this += t;
1376 }
1377
1378 prec_elem = cpp_dec_float_elem_number;
1379
1380 return *this;
1381 }
1382
1383 template <unsigned Digits10, class ExponentType, class Allocator>
1384 int cpp_dec_float<Digits10, ExponentType, Allocator>::compare(const cpp_dec_float& v) const
1385 {
1386
1387
1388
1389
1390
1391
1392 if ((!(isfinite)()) || (!(v.isfinite)()))
1393 {
1394
1395
1396
1397 if ((isnan)() || (v.isnan)())
1398 {
1399 return ((isnan)() ? 1 : -1);
1400 }
1401
1402 if ((isinf)() && (v.isinf)())
1403 {
1404
1405
1406 return ((neg == v.neg) ? 0 : (neg ? -1 : 1));
1407 }
1408
1409 if ((isinf)())
1410 {
1411
1412
1413
1414 return (isneg() ? -1 : 1);
1415 }
1416 else
1417 {
1418
1419
1420
1421 return (v.neg ? 1 : -1);
1422 }
1423 }
1424
1425
1426 if (iszero())
1427 {
1428
1429 return (v.iszero() ? 0
1430 : (v.neg ? 1 : -1));
1431 }
1432 else if (v.iszero())
1433 {
1434
1435 return (neg ? -1 : 1);
1436 }
1437 else
1438 {
1439
1440
1441 if (neg != v.neg)
1442 {
1443
1444 return (neg ? -1 : 1);
1445 }
1446 else if (exp != v.exp)
1447 {
1448
1449 const int val_cexpression = ((exp < v.exp) ? 1 : -1);
1450
1451 return (neg ? val_cexpression : -val_cexpression);
1452 }
1453 else
1454 {
1455
1456
1457 const int val_cmp_data = compare_ranges(data.cbegin(), v.data.cbegin());
1458
1459 return ((!neg) ? val_cmp_data : -val_cmp_data);
1460 }
1461 }
1462 }
1463
1464 template <unsigned Digits10, class ExponentType, class Allocator>
1465 bool cpp_dec_float<Digits10, ExponentType, Allocator>::isone() const
1466 {
1467
1468
1469 const bool not_negative_and_is_finite = ((!neg) && (isfinite)());
1470
1471 if (not_negative_and_is_finite)
1472 {
1473 if ((data[0u] == static_cast<std::uint32_t>(1u)) && (exp == static_cast<exponent_type>(0)))
1474 {
1475 const typename array_type::const_iterator it_non_zero = std::find_if(data.begin(), data.end(), data_elem_is_non_zero_predicate);
1476 return (it_non_zero == data.end());
1477 }
1478 else if ((data[0u] == static_cast<std::uint32_t>(cpp_dec_float_elem_mask - 1)) && (exp == static_cast<exponent_type>(-cpp_dec_float_elem_digits10)))
1479 {
1480 const typename array_type::const_iterator it_non_nine = std::find_if(data.begin(), data.end(), data_elem_is_non_nine_predicate);
1481 return (it_non_nine == data.end());
1482 }
1483 }
1484
1485 return false;
1486 }
1487
1488 template <unsigned Digits10, class ExponentType, class Allocator>
1489 bool cpp_dec_float<Digits10, ExponentType, Allocator>::isint() const
1490 {
1491 if (fpclass != cpp_dec_float_finite)
1492 {
1493 return false;
1494 }
1495
1496 if (iszero())
1497 {
1498 return true;
1499 }
1500
1501 if (exp < static_cast<exponent_type>(0))
1502 {
1503 return false;
1504 }
1505
1506 const typename array_type::size_type offset_decimal_part = static_cast<typename array_type::size_type>(exp / cpp_dec_float_elem_digits10) + 1u;
1507
1508 if (offset_decimal_part >= static_cast<typename array_type::size_type>(cpp_dec_float_elem_number))
1509 {
1510
1511
1512 return true;
1513 }
1514
1515 typename array_type::const_iterator it_non_zero = std::find_if(data.begin() + static_cast<std::ptrdiff_t>(offset_decimal_part), data.end(), data_elem_is_non_zero_predicate);
1516
1517 return (it_non_zero == data.end());
1518 }
1519
1520 template <unsigned Digits10, class ExponentType, class Allocator>
1521 void cpp_dec_float<Digits10, ExponentType, Allocator>::extract_parts(double& mantissa, ExponentType& exponent) const
1522 {
1523
1524
1525
1526 exponent = exp;
1527
1528 std::uint32_t p10 = static_cast<std::uint32_t>(1u);
1529 std::uint32_t test = data[0u];
1530
1531 for (;;)
1532 {
1533 test /= static_cast<std::uint32_t>(10u);
1534
1535 if (test == static_cast<std::uint32_t>(0u))
1536 {
1537 break;
1538 }
1539
1540 p10 *= static_cast<std::uint32_t>(10u);
1541 ++exponent;
1542 }
1543
1544
1545 const int max_elem_in_double_count = static_cast<int>(static_cast<std::int32_t>(std::numeric_limits<double>::digits10) / cpp_dec_float_elem_digits10) + (static_cast<int>(static_cast<std::int32_t>(std::numeric_limits<double>::digits10) % cpp_dec_float_elem_digits10) != 0 ? 1 : 0) + 1;
1546
1547
1548 const std::size_t max_elem_extract_count = static_cast<std::size_t>((std::min)(static_cast<std::int32_t>(max_elem_in_double_count), cpp_dec_float_elem_number));
1549
1550
1551 mantissa = static_cast<double>(data[0]);
1552 double scale = 1.0;
1553
1554
1555 for (std::size_t i = 1u; i < max_elem_extract_count; i++)
1556 {
1557 scale /= static_cast<double>(cpp_dec_float_elem_mask);
1558 mantissa += (static_cast<double>(data[i]) * scale);
1559 }
1560
1561 mantissa /= static_cast<double>(p10);
1562
1563 if (neg)
1564 {
1565 mantissa = -mantissa;
1566 }
1567 }
1568
1569 template <unsigned Digits10, class ExponentType, class Allocator>
1570 double cpp_dec_float<Digits10, ExponentType, Allocator>::extract_double() const
1571 {
1572
1573
1574
1575 if (!(isfinite)())
1576 {
1577 if ((isnan)())
1578 {
1579 return std::numeric_limits<double>::quiet_NaN();
1580 }
1581 else
1582 {
1583 return ((!neg) ? std::numeric_limits<double>::infinity()
1584 : -std::numeric_limits<double>::infinity());
1585 }
1586 }
1587
1588 cpp_dec_float<Digits10, ExponentType, Allocator> xx(*this);
1589 if (xx.isneg())
1590 xx.negate();
1591
1592
1593 if (iszero() || (xx.compare(double_min()) < 0))
1594 {
1595 return 0.0;
1596 }
1597
1598
1599 if (xx.compare(double_max()) > 0)
1600 {
1601 return ((!neg) ? std::numeric_limits<double>::infinity()
1602 : -std::numeric_limits<double>::infinity());
1603 }
1604
1605 std::stringstream ss;
1606 ss.imbue(std::locale::classic());
1607
1608 ss << str(std::numeric_limits<double>::digits10 + (2 + 1), std::ios_base::scientific);
1609
1610 double d;
1611 ss >> d;
1612
1613 return d;
1614 }
1615
1616 template <unsigned Digits10, class ExponentType, class Allocator>
1617 long double cpp_dec_float<Digits10, ExponentType, Allocator>::extract_long_double() const
1618 {
1619
1620
1621
1622 if (!(isfinite)())
1623 {
1624 if ((isnan)())
1625 {
1626 return std::numeric_limits<long double>::quiet_NaN();
1627 }
1628 else
1629 {
1630 return ((!neg) ? std::numeric_limits<long double>::infinity()
1631 : -std::numeric_limits<long double>::infinity());
1632 }
1633 }
1634
1635 cpp_dec_float<Digits10, ExponentType, Allocator> xx(*this);
1636 if (xx.isneg())
1637 xx.negate();
1638
1639
1640 if (iszero() || (xx.compare(long_double_min()) < 0))
1641 {
1642 return static_cast<long double>(0.0);
1643 }
1644
1645
1646 if (xx.compare(long_double_max()) > 0)
1647 {
1648 return ((!neg) ? std::numeric_limits<long double>::infinity()
1649 : -std::numeric_limits<long double>::infinity());
1650 }
1651
1652 std::stringstream ss;
1653 ss.imbue(std::locale::classic());
1654
1655 ss << str(std::numeric_limits<long double>::digits10 + (2 + 1), std::ios_base::scientific);
1656
1657 long double ld;
1658 ss >> ld;
1659
1660 return ld;
1661 }
1662
1663 template <unsigned Digits10, class ExponentType, class Allocator>
1664 long long cpp_dec_float<Digits10, ExponentType, Allocator>::extract_signed_long_long() const
1665 {
1666
1667
1668
1669
1670 if (exp < static_cast<exponent_type>(0))
1671 {
1672 return static_cast<long long>(0);
1673 }
1674
1675 const bool b_neg = isneg();
1676
1677 unsigned long long val;
1678
1679 if ((!b_neg) && (compare(long_long_max()) > 0))
1680 {
1681 return (std::numeric_limits<long long>::max)();
1682 }
1683 else if (b_neg && (compare(long_long_min()) < 0))
1684 {
1685 return (std::numeric_limits<long long>::min)();
1686 }
1687 else
1688 {
1689
1690 cpp_dec_float<Digits10, ExponentType, Allocator> xn(extract_integer_part());
1691 if (xn.isneg())
1692 xn.negate();
1693
1694 val = static_cast<unsigned long long>(xn.data[0]);
1695
1696 const std::int32_t imax = (std::min)(static_cast<std::int32_t>(static_cast<std::int32_t>(xn.exp) / cpp_dec_float_elem_digits10), static_cast<std::int32_t>(cpp_dec_float_elem_number - static_cast<std::int32_t>(1)));
1697
1698 for (std::int32_t i = static_cast<std::int32_t>(1); i <= imax; i++)
1699 {
1700 val *= static_cast<unsigned long long>(cpp_dec_float_elem_mask);
1701 val += static_cast<unsigned long long>(xn.data[static_cast<std::size_t>(i)]);
1702 }
1703 }
1704
1705 if (!b_neg)
1706 {
1707 return static_cast<long long>(val);
1708 }
1709 else
1710 {
1711
1712
1713
1714
1715 long long sval = static_cast<long long>(val - 1);
1716 sval = -sval;
1717 --sval;
1718 return sval;
1719 }
1720 }
1721
1722 template <unsigned Digits10, class ExponentType, class Allocator>
1723 unsigned long long cpp_dec_float<Digits10, ExponentType, Allocator>::extract_unsigned_long_long() const
1724 {
1725
1726
1727
1728
1729
1730
1731 if (isneg())
1732 {
1733 return static_cast<unsigned long long>(extract_signed_long_long());
1734 }
1735
1736 if (exp < static_cast<exponent_type>(0))
1737 {
1738 return static_cast<unsigned long long>(0u);
1739 }
1740
1741 const cpp_dec_float<Digits10, ExponentType, Allocator> xn(extract_integer_part());
1742
1743 unsigned long long val;
1744
1745 if (xn.compare(ulong_long_max()) > 0)
1746 {
1747 return (std::numeric_limits<unsigned long long>::max)();
1748 }
1749 else
1750 {
1751
1752 val = static_cast<unsigned long long>(xn.data[0]);
1753
1754 const std::int32_t imax = (std::min)(static_cast<std::int32_t>(static_cast<std::int32_t>(xn.exp) / cpp_dec_float_elem_digits10), static_cast<std::int32_t>(cpp_dec_float_elem_number - static_cast<std::int32_t>(1)));
1755
1756 for (std::int32_t i = static_cast<std::int32_t>(1); i <= imax; i++)
1757 {
1758 val *= static_cast<unsigned long long>(cpp_dec_float_elem_mask);
1759 val += static_cast<unsigned long long>(xn.data[i]);
1760 }
1761 }
1762
1763 return val;
1764 }
1765
1766 #ifdef BOOST_HAS_INT128
1767
1768 template <unsigned Digits10, class ExponentType, class Allocator>
1769 int128_type cpp_dec_float<Digits10, ExponentType, Allocator>::extract_signed_int128() const
1770 {
1771
1772
1773
1774
1775 if (exp < static_cast<exponent_type>(0))
1776 {
1777 return static_cast<int128_type>(0);
1778 }
1779
1780 const bool b_neg = isneg();
1781 cpp_dec_float<Digits10, ExponentType, Allocator> i128max;
1782 i128max = ((~static_cast<uint128_type>(0)) >> 1);
1783 cpp_dec_float<Digits10, ExponentType, Allocator> i128min;
1784 i128min = (-1 - static_cast<int128_type>((static_cast<uint128_type>(1) << 127) - 1));
1785
1786 uint128_type val;
1787
1788 if ((!b_neg) && (compare(i128max) > 0))
1789 {
1790 return ((~static_cast<uint128_type>(0)) >> 1);
1791 }
1792 else if (b_neg && (compare(i128min) < 0))
1793 {
1794 return (-1 - static_cast<int128_type>((static_cast<uint128_type>(1) << 127) - 1));
1795 }
1796 else
1797 {
1798
1799 cpp_dec_float<Digits10, ExponentType, Allocator> xn(extract_integer_part());
1800 if (xn.isneg())
1801 xn.negate();
1802
1803 val = static_cast<uint128_type>(xn.data[0]);
1804
1805 const std::int32_t imax = (std::min)(static_cast<std::int32_t>(static_cast<std::int32_t>(xn.exp) / cpp_dec_float_elem_digits10), static_cast<std::int32_t>(cpp_dec_float_elem_number - static_cast<std::int32_t>(1)));
1806
1807 for (std::int32_t i = static_cast<std::int32_t>(1); i <= imax; i++)
1808 {
1809 val *= static_cast<uint128_type>(cpp_dec_float_elem_mask);
1810 val += static_cast<uint128_type>(xn.data[static_cast<std::size_t>(i)]);
1811 }
1812 }
1813
1814 if (!b_neg)
1815 {
1816 return static_cast<int128_type>(val);
1817 }
1818 else
1819 {
1820
1821
1822
1823
1824 int128_type sval = static_cast<int128_type>(val - 1);
1825 sval = -sval;
1826 --sval;
1827 return sval;
1828 }
1829 }
1830
1831 template <unsigned Digits10, class ExponentType, class Allocator>
1832 uint128_type cpp_dec_float<Digits10, ExponentType, Allocator>::extract_unsigned_int128() const
1833 {
1834
1835
1836
1837
1838
1839
1840 if (isneg())
1841 {
1842 return static_cast<uint128_type>(extract_signed_int128());
1843 }
1844
1845 if (exp < static_cast<exponent_type>(0))
1846 {
1847 return 0u;
1848 }
1849
1850 const cpp_dec_float<Digits10, ExponentType, Allocator> xn(extract_integer_part());
1851 cpp_dec_float<Digits10, ExponentType, Allocator> i128max;
1852 i128max = (~static_cast<uint128_type>(0));
1853
1854 uint128_type val;
1855
1856 if (xn.compare(i128max) > 0)
1857 {
1858 return (~static_cast<uint128_type>(0));
1859 }
1860 else
1861 {
1862
1863 val = static_cast<uint128_type>(xn.data[0]);
1864
1865 const std::int32_t imax = (std::min)(static_cast<std::int32_t>(static_cast<std::int32_t>(xn.exp) / cpp_dec_float_elem_digits10), static_cast<std::int32_t>(cpp_dec_float_elem_number - static_cast<std::int32_t>(1)));
1866
1867 for (std::int32_t i = static_cast<std::int32_t>(1); i <= imax; i++)
1868 {
1869 val *= static_cast<uint128_type>(cpp_dec_float_elem_mask);
1870 val += static_cast<uint128_type>(xn.data[i]);
1871 }
1872 }
1873
1874 return val;
1875 }
1876
1877 #endif
1878
1879 template <unsigned Digits10, class ExponentType, class Allocator>
1880 cpp_dec_float<Digits10, ExponentType, Allocator> cpp_dec_float<Digits10, ExponentType, Allocator>::extract_integer_part() const
1881 {
1882
1883
1884 if (!(isfinite)())
1885 {
1886 return *this;
1887 }
1888
1889 if (exp < static_cast<ExponentType>(0))
1890 {
1891
1892
1893 return zero();
1894 }
1895
1896
1897
1898
1899
1900 cpp_dec_float<Digits10, ExponentType, Allocator> x = *this;
1901
1902
1903 const std::size_t first_clear = (static_cast<std::size_t>(x.exp) / static_cast<std::size_t>(cpp_dec_float_elem_digits10)) + 1u;
1904 const std::size_t last_clear = static_cast<std::size_t>(cpp_dec_float_elem_number);
1905
1906 if (first_clear < last_clear)
1907 std::fill(x.data.begin() + static_cast<std::ptrdiff_t>(first_clear), x.data.begin() + static_cast<std::ptrdiff_t>(last_clear), static_cast<std::uint32_t>(0u));
1908
1909 return x;
1910 }
1911
1912 template <unsigned Digits10, class ExponentType, class Allocator>
1913 std::string cpp_dec_float<Digits10, ExponentType, Allocator>::str(std::intmax_t number_of_digits, std::ios_base::fmtflags f) const
1914 {
1915 if ((this->isinf)())
1916 {
1917 if (this->isneg())
1918 return "-inf";
1919 else if (f & std::ios_base::showpos)
1920 return "+inf";
1921 else
1922 return "inf";
1923 }
1924 else if ((this->isnan)())
1925 {
1926 return "nan";
1927 }
1928
1929 std::string str;
1930 std::intmax_t org_digits(number_of_digits);
1931 exponent_type my_exp = order();
1932
1933 if (!(f & std::ios_base::fixed) && (number_of_digits == 0))
1934 number_of_digits = cpp_dec_float_max_digits10;
1935
1936 if (f & std::ios_base::fixed)
1937 {
1938 number_of_digits += my_exp + 1;
1939 }
1940 else if (f & std::ios_base::scientific)
1941 ++number_of_digits;
1942
1943 const std::size_t number_of_elements = (std::min)(static_cast<std::size_t>(static_cast<std::size_t>(number_of_digits / static_cast<std::intmax_t>(cpp_dec_float_elem_digits10)) + 2u),
1944 static_cast<std::size_t>(cpp_dec_float_elem_number));
1945
1946
1947 std::stringstream ss;
1948 ss.imbue(std::locale::classic());
1949 ss << data[0];
1950
1951 for (std::size_t i = static_cast<std::size_t>(1u); i < number_of_elements; i++)
1952 {
1953 ss << std::setw(static_cast<std::streamsize>(cpp_dec_float_elem_digits10))
1954 << std::setfill(static_cast<char>('0'))
1955 << data[i];
1956 }
1957 str += ss.str();
1958
1959 bool have_leading_zeros = false;
1960
1961 if (number_of_digits == 0)
1962 {
1963
1964
1965 number_of_digits -= my_exp + 1;
1966 if (number_of_digits)
1967 {
1968 str.insert(static_cast<std::string::size_type>(0), std::string::size_type(number_of_digits), '0');
1969 have_leading_zeros = true;
1970 }
1971 }
1972
1973 if (number_of_digits < 0)
1974 {
1975 str = "0";
1976 if (isneg())
1977 str.insert(static_cast<std::string::size_type>(0), 1, '-');
1978 boost::multiprecision::detail::format_float_string(str, 0, number_of_digits - my_exp - 1, f, this->iszero());
1979 return str;
1980 }
1981 else
1982 {
1983
1984 if (str.length() > static_cast<std::string::size_type>(number_of_digits))
1985 {
1986
1987 const std::uint32_t round = static_cast<std::uint32_t>(static_cast<std::uint32_t>(str[static_cast<std::string::size_type>(number_of_digits)]) - static_cast<std::uint32_t>('0'));
1988
1989 bool need_round_up = round >= 5u;
1990
1991 if (round == 5u)
1992 {
1993 const std::uint32_t ix = number_of_digits == 0 ? 0 : static_cast<std::uint32_t>(static_cast<std::uint32_t>(str[static_cast<std::string::size_type>(number_of_digits - 1)]) - static_cast<std::uint32_t>('0'));
1994 if ((ix & 1u) == 0)
1995 {
1996
1997
1998 if (str.find_first_not_of('0', static_cast<std::string::size_type>(number_of_digits + 1)) == std::string::npos)
1999 {
2000 bool all_zeros = true;
2001
2002 for (std::size_t i = number_of_elements; i < data.size(); i++)
2003 {
2004 if (data[i])
2005 {
2006 all_zeros = false;
2007 break;
2008 }
2009 }
2010 if (all_zeros)
2011 need_round_up = false;
2012 }
2013 }
2014 }
2015
2016
2017 str.erase(static_cast<std::string::size_type>(number_of_digits));
2018
2019 if (need_round_up)
2020 {
2021 if (str.size())
2022 {
2023 std::size_t ix = static_cast<std::size_t>(str.length() - 1u);
2024
2025
2026 while (ix && (static_cast<std::int32_t>(str.at(ix)) - static_cast<std::int32_t>('0') == static_cast<std::int32_t>(9)))
2027 {
2028 str.at(ix) = static_cast<char>('0');
2029 --ix;
2030 }
2031
2032 if (!ix)
2033 {
2034
2035 if (static_cast<std::int32_t>(static_cast<std::int32_t>(str.at(ix)) - static_cast<std::int32_t>(0x30)) == static_cast<std::int32_t>(9))
2036 {
2037
2038 str.at(ix) = static_cast<char>('1');
2039 ++my_exp;
2040 }
2041 else
2042 {
2043
2044 ++str.at(ix);
2045 }
2046 }
2047 else
2048 {
2049
2050 ++str[ix];
2051 }
2052 }
2053 else
2054 {
2055 str = "1";
2056 ++my_exp;
2057 }
2058 }
2059 }
2060 }
2061
2062 if (have_leading_zeros)
2063 {
2064
2065
2066 if (str[std::string::size_type(number_of_digits - 1)] != '0')
2067 {
2068 ++my_exp;
2069 str.erase(0, std::string::size_type(number_of_digits - 1));
2070 }
2071 else
2072 str.erase(0, std::string::size_type(number_of_digits));
2073 }
2074
2075 if (isneg())
2076 str.insert(static_cast<std::string::size_type>(0), 1, '-');
2077
2078 boost::multiprecision::detail::format_float_string(str, my_exp, org_digits, f, this->iszero());
2079 return str;
2080 }
2081
2082 template <unsigned Digits10, class ExponentType, class Allocator>
2083 bool cpp_dec_float<Digits10, ExponentType, Allocator>::rd_string(const char* const s)
2084 {
2085 #ifndef BOOST_NO_EXCEPTIONS
2086 try
2087 {
2088 #endif
2089
2090 std::string str(s);
2091 static const std::string valid_characters{"0123456789"};
2092
2093
2094
2095
2096
2097 exp = static_cast<exponent_type>(0);
2098
2099 std::size_t pos;
2100
2101 if (((pos = str.find('e')) != std::string::npos) || ((pos = str.find('E')) != std::string::npos))
2102 {
2103
2104 #ifndef BOOST_MP_STANDALONE
2105 exp = boost::lexical_cast<exponent_type>(static_cast<const char*>(str.c_str() + (pos + 1u)));
2106 #else
2107 if (str.find_first_not_of(valid_characters, ((str[pos + 1] == '+') || (str[pos + 1] == '-')) ? pos + 2 : pos + 1) != std::string::npos)
2108 BOOST_MP_THROW_EXCEPTION(std::runtime_error("Can not construct a floating point with non-numeric content"));
2109 exp = static_cast<exponent_type>(std::atoll(static_cast<const char*>(str.c_str() + (pos + 1u))));
2110 #endif
2111
2112 str = str.substr(static_cast<std::size_t>(0u), pos);
2113 }
2114
2115
2116 neg = false;
2117
2118 if (str.size())
2119 {
2120 if (str[0] == '-')
2121 {
2122 neg = true;
2123 str.erase(0, 1);
2124 }
2125 else if (str[0] == '+')
2126 {
2127 str.erase(0, 1);
2128 }
2129 }
2130
2131
2132
2133 if ((str == "inf") || (str == "INF") || (str == "infinity") || (str == "INFINITY"))
2134 {
2135 if (neg)
2136 {
2137 *this = this->inf();
2138 this->negate();
2139 }
2140 else
2141 *this = this->inf();
2142 return true;
2143 }
2144 if ((str.size() >= 3) && ((str.substr(0, 3) == "nan") || (str.substr(0, 3) == "NAN") || (str.substr(0, 3) == "NaN")))
2145 {
2146 *this = this->nan();
2147 return true;
2148 }
2149
2150
2151 const std::string::iterator fwd_it_leading_zero = std::find_if(str.begin(), str.end(), char_is_nonzero_predicate);
2152
2153 if (fwd_it_leading_zero != str.begin())
2154 {
2155 if (fwd_it_leading_zero == str.end())
2156 {
2157
2158
2159 operator=(zero());
2160 return true;
2161 }
2162 else
2163 {
2164 str.erase(str.begin(), fwd_it_leading_zero);
2165 }
2166 }
2167
2168
2169
2170
2171
2172
2173
2174
2175 pos = str.find(static_cast<char>('.'));
2176
2177 if (pos != std::string::npos)
2178 {
2179
2180 if (str.find_first_not_of(valid_characters) != pos)
2181 BOOST_MP_THROW_EXCEPTION(std::runtime_error("Can not construct a floating point with non-numeric content"));
2182 if (str.find_first_not_of(valid_characters, pos + 1) != std::string::npos)
2183 BOOST_MP_THROW_EXCEPTION(std::runtime_error("Can not construct a floating point with non-numeric content"));
2184
2185
2186 const std::string::const_reverse_iterator rit_non_zero = std::find_if(str.rbegin(), str.rend(), char_is_nonzero_predicate);
2187
2188 if (rit_non_zero != static_cast<std::string::const_reverse_iterator>(str.rbegin()))
2189 {
2190 const std::string::size_type ofs =
2191 static_cast<std::string::size_type>
2192 (
2193 static_cast<std::ptrdiff_t>(str.length())
2194 - std::distance<std::string::const_reverse_iterator>(str.rbegin(), rit_non_zero)
2195 );
2196 str.erase(str.begin() + static_cast<std::ptrdiff_t>(ofs), str.end());
2197 }
2198
2199
2200 if (str == std::string("."))
2201 {
2202 operator=(zero());
2203 return true;
2204 }
2205
2206
2207
2208
2209
2210 if (str.at(static_cast<std::size_t>(0u)) == static_cast<char>('.'))
2211 {
2212 const std::string::iterator it_non_zero = std::find_if(str.begin() + 1u, str.end(), char_is_nonzero_predicate);
2213
2214 std::size_t delta_exp = static_cast<std::size_t>(0u);
2215
2216 if (str.at(static_cast<std::size_t>(1u)) == static_cast<char>('0'))
2217 {
2218 delta_exp = static_cast<std::size_t>(std::distance<std::string::const_iterator>(str.begin() + 1u, it_non_zero));
2219 }
2220
2221
2222 str.erase(str.begin(), it_non_zero);
2223 str.insert(static_cast<std::string::size_type>(1u), ".");
2224 exp -= static_cast<exponent_type>(delta_exp + 1u);
2225 }
2226 }
2227 else
2228 {
2229
2230 if (str.find_first_not_of(valid_characters) != std::string::npos)
2231 BOOST_MP_THROW_EXCEPTION(std::runtime_error("Can not construct a floating point with non-numeric content"));
2232
2233
2234 str.append(".");
2235 }
2236
2237
2238 std::ptrdiff_t n_shift = static_cast<std::ptrdiff_t>(0);
2239 const std::ptrdiff_t n_exp_rem = static_cast<std::ptrdiff_t>(exp % static_cast<exponent_type>(cpp_dec_float_elem_digits10));
2240
2241 if((exp % static_cast<exponent_type>(cpp_dec_float_elem_digits10)) != static_cast<exponent_type>(0))
2242 {
2243 n_shift = ((exp < static_cast<exponent_type>(0))
2244 ? static_cast<std::ptrdiff_t>(n_exp_rem + static_cast<std::ptrdiff_t>(cpp_dec_float_elem_digits10))
2245 : static_cast<std::ptrdiff_t>(n_exp_rem));
2246 }
2247
2248
2249 pos = str.find(static_cast<char>('.'));
2250
2251 std::ptrdiff_t pos_plus_one = static_cast<std::ptrdiff_t>(pos + 1);
2252
2253 if ((static_cast<std::ptrdiff_t>(str.length()) - pos_plus_one) < n_shift)
2254 {
2255 const std::ptrdiff_t sz = static_cast<std::ptrdiff_t>(n_shift - (static_cast<std::ptrdiff_t>(str.length()) - pos_plus_one));
2256
2257 str.append(std::string(static_cast<std::string::size_type>(sz), static_cast<char>('0')));
2258 }
2259
2260
2261 if (n_shift != static_cast<std::ptrdiff_t>(0))
2262 {
2263 str.insert(static_cast<std::string::size_type>(pos_plus_one + n_shift), ".");
2264
2265 str.erase(pos, static_cast<std::ptrdiff_t>(1));
2266
2267 exp -= static_cast<exponent_type>(n_shift);
2268 }
2269
2270
2271 pos = str.find(static_cast<char>('.'));
2272 pos_plus_one = static_cast<std::ptrdiff_t>(pos + 1u);
2273
2274 if (pos > static_cast<std::size_t>(cpp_dec_float_elem_digits10))
2275 {
2276 const std::int32_t n_pos = static_cast<std::int32_t>(pos);
2277 const std::int32_t n_rem_is_zero = ((static_cast<std::int32_t>(n_pos % cpp_dec_float_elem_digits10) == static_cast<std::int32_t>(0)) ? static_cast<std::int32_t>(1) : static_cast<std::int32_t>(0));
2278 const std::int32_t n = static_cast<std::int32_t>(static_cast<std::int32_t>(n_pos / cpp_dec_float_elem_digits10) - n_rem_is_zero);
2279
2280 str.insert(static_cast<std::size_t>(static_cast<std::int32_t>(n_pos - static_cast<std::int32_t>(n * cpp_dec_float_elem_digits10))), ".");
2281
2282 str.erase(static_cast<std::size_t>(pos_plus_one), static_cast<std::size_t>(1u));
2283
2284 exp += static_cast<exponent_type>(static_cast<exponent_type>(n) * static_cast<exponent_type>(cpp_dec_float_elem_digits10));
2285 }
2286
2287
2288
2289 pos = str.find(static_cast<char>('.'));
2290 pos_plus_one = static_cast<std::ptrdiff_t>(pos + 1u);
2291
2292
2293 if(pos != std::string::npos && (str.back() == 'L' || str.back() == 'l' || str.back() == 'u' || str.back() == 'U'))
2294 {
2295 BOOST_MP_THROW_EXCEPTION(std::runtime_error("Can not construct a floating point with an integer literal"));
2296 }
2297
2298 const std::int32_t n_dec = static_cast<std::int32_t>(static_cast<std::int32_t>(str.length() - 1u) - static_cast<std::int32_t>(pos));
2299 const std::int32_t n_rem = static_cast<std::int32_t>(n_dec % cpp_dec_float_elem_digits10);
2300
2301 std::int32_t n_cnt = ((n_rem != static_cast<std::int32_t>(0))
2302 ? static_cast<std::int32_t>(cpp_dec_float_elem_digits10 - n_rem)
2303 : static_cast<std::int32_t>(0));
2304
2305 if (n_cnt != static_cast<std::int32_t>(0))
2306 {
2307 str.append(static_cast<std::size_t>(n_cnt), static_cast<char>('0'));
2308 }
2309
2310
2311 const std::size_t max_dec = static_cast<std::size_t>((cpp_dec_float_elem_number - 1) * cpp_dec_float_elem_digits10);
2312
2313 if (static_cast<std::size_t>(str.length() - pos) > max_dec)
2314 {
2315 str = str.substr(static_cast<std::size_t>(0u),
2316 static_cast<std::size_t>(pos_plus_one + static_cast<std::ptrdiff_t>(max_dec)));
2317 }
2318
2319
2320
2321
2322
2323 std::fill(data.begin(), data.end(), static_cast<std::uint32_t>(0u));
2324
2325
2326
2327
2328 data[0u] = static_cast<std::uint32_t>(std::stol(str.substr(static_cast<std::size_t>(0u), pos)));
2329
2330
2331 const std::string::size_type i_end =
2332 (
2333 static_cast<std::string::size_type>(str.length() - static_cast<std::string::size_type>(pos_plus_one))
2334 / static_cast<std::string::size_type>(cpp_dec_float_elem_digits10)
2335 );
2336
2337 for (std::string::size_type i = static_cast<std::string::size_type>(0u); i < i_end; i++)
2338 {
2339 const std::string::const_iterator it =
2340 str.begin()
2341 + static_cast<std::ptrdiff_t>
2342 (
2343 static_cast<std::string::size_type>(pos_plus_one)
2344 + static_cast<std::string::size_type>(i * static_cast<std::string::size_type>(cpp_dec_float_elem_digits10))
2345 );
2346
2347 data[i + 1u] = static_cast<std::uint32_t>(std::stol(std::string(it, it + static_cast<std::string::size_type>(cpp_dec_float_elem_digits10))));
2348 }
2349
2350
2351 if (exp > cpp_dec_float_max_exp10)
2352 {
2353 const bool b_result_is_neg = neg;
2354
2355 *this = inf();
2356 if (b_result_is_neg)
2357 negate();
2358 }
2359
2360
2361 if (exp <= cpp_dec_float_min_exp10)
2362 {
2363 if (exp == cpp_dec_float_min_exp10)
2364 {
2365
2366 cpp_dec_float<Digits10, ExponentType, Allocator> test = *this;
2367
2368 test.exp = static_cast<exponent_type>(0);
2369
2370 if (test.isone())
2371 {
2372 *this = zero();
2373 }
2374 }
2375 else
2376 {
2377 *this = zero();
2378 }
2379 }
2380
2381 #ifndef BOOST_NO_EXCEPTIONS
2382 }
2383 #ifndef BOOST_MP_STANDALONE
2384 catch (const bad_lexical_cast&)
2385 #else
2386 catch (const std::exception&)
2387 #endif
2388 {
2389
2390 std::string msg = "Unable to parse the string \"";
2391 msg += s;
2392 msg += "\" as a floating point value.";
2393 throw std::runtime_error(msg);
2394 }
2395 #endif
2396 return true;
2397 }
2398
2399 template <unsigned Digits10, class ExponentType, class Allocator>
2400 cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float(const double mantissa, const ExponentType exponent)
2401 : data(),
2402 exp(static_cast<ExponentType>(0)),
2403 neg(false),
2404 fpclass(cpp_dec_float_finite),
2405 prec_elem(cpp_dec_float_elem_number)
2406 {
2407
2408
2409
2410 const bool mantissa_is_iszero = (::fabs(mantissa) < ((std::numeric_limits<double>::min)() * (1.0 + std::numeric_limits<double>::epsilon())));
2411
2412 if (mantissa_is_iszero)
2413 {
2414 std::fill(data.begin(), data.end(), static_cast<std::uint32_t>(0u));
2415 return;
2416 }
2417
2418 const bool b_neg = (mantissa < 0.0);
2419
2420 double d = ((!b_neg) ? mantissa : -mantissa);
2421 exponent_type e = exponent;
2422
2423 while (d > 10.0)
2424 {
2425 d /= 10.0;
2426 ++e;
2427 }
2428 while (d < 1.0)
2429 {
2430 d *= 10.0;
2431 --e;
2432 }
2433
2434 std::int32_t shift = static_cast<std::int32_t>(e % static_cast<std::int32_t>(cpp_dec_float_elem_digits10));
2435
2436 while (static_cast<std::int32_t>(shift-- % cpp_dec_float_elem_digits10) != static_cast<std::int32_t>(0))
2437 {
2438 d *= 10.0;
2439 --e;
2440 }
2441
2442 exp = e;
2443 neg = b_neg;
2444
2445 std::fill(data.begin(), data.end(), static_cast<std::uint32_t>(0u));
2446
2447 constexpr std::int32_t digit_ratio = static_cast<std::int32_t>(static_cast<std::int32_t>(std::numeric_limits<double>::digits10) / static_cast<std::int32_t>(cpp_dec_float_elem_digits10));
2448 constexpr std::int32_t digit_loops = static_cast<std::int32_t>(digit_ratio + static_cast<std::int32_t>(2));
2449
2450 for (std::int32_t i = static_cast<std::int32_t>(0); i < digit_loops; i++)
2451 {
2452 std::uint32_t n = static_cast<std::uint32_t>(static_cast<std::uint64_t>(d));
2453 data[static_cast<std::size_t>(i)] = static_cast<std::uint32_t>(n);
2454 d -= static_cast<double>(n);
2455 d *= static_cast<double>(cpp_dec_float_elem_mask);
2456 }
2457 }
2458
2459 template <unsigned Digits10, class ExponentType, class Allocator>
2460 template <class Float>
2461 typename std::enable_if<std::is_floating_point<Float>::value, cpp_dec_float<Digits10, ExponentType, Allocator>&>::type cpp_dec_float<Digits10, ExponentType, Allocator>::operator=(Float a)
2462 {
2463
2464
2465 BOOST_MP_FLOAT128_USING
2466 using std::floor;
2467 using std::frexp;
2468 using std::ldexp;
2469
2470 if (a == 0)
2471 return *this = zero();
2472
2473 if (a == 1)
2474 return *this = one();
2475
2476 if (BOOST_MP_ISINF(a))
2477 {
2478 *this = inf();
2479 if (a < 0)
2480 this->negate();
2481 return *this;
2482 }
2483
2484 if (BOOST_MP_ISNAN(a))
2485 return *this = nan();
2486
2487 int e;
2488 Float f, term;
2489 *this = zero();
2490
2491 f = frexp(a, &e);
2492
2493 BOOST_MP_ASSERT(!BOOST_MP_ISNAN(f) && !BOOST_MP_ISINF(f));
2494
2495 constexpr int shift = std::numeric_limits<int>::digits - 1;
2496
2497 while (f != static_cast<Float>(0.0f))
2498 {
2499
2500 f = ldexp(f, shift);
2501 BOOST_MP_ASSERT(!BOOST_MP_ISNAN(f) && !BOOST_MP_ISINF(f));
2502 term = floor(f);
2503 e -= shift;
2504 *this *= pow2(shift);
2505 if (term > 0)
2506 add_unsigned_long_long(static_cast<unsigned>(term));
2507 else
2508 sub_unsigned_long_long(static_cast<unsigned>(-term));
2509 f -= term;
2510 }
2511
2512 if (e != 0)
2513 *this *= pow2(e);
2514
2515 return *this;
2516 }
2517
2518 template <unsigned Digits10, class ExponentType, class Allocator>
2519 void cpp_dec_float<Digits10, ExponentType, Allocator>::from_unsigned_long_long(const unsigned long long u)
2520 {
2521 std::fill(data.begin(), data.end(), static_cast<std::uint32_t>(0u));
2522
2523 exp = static_cast<exponent_type>(0);
2524 neg = false;
2525 fpclass = cpp_dec_float_finite;
2526 prec_elem = cpp_dec_float_elem_number;
2527
2528 if (u == 0)
2529 {
2530 return;
2531 }
2532
2533 std::size_t i = static_cast<std::size_t>(0u);
2534
2535 unsigned long long uu = u;
2536
2537 std::uint32_t temp[(std::numeric_limits<unsigned long long>::digits10 / static_cast<int>(cpp_dec_float_elem_digits10)) + 3] = {static_cast<std::uint32_t>(0u)};
2538
2539 while (uu != static_cast<unsigned long long>(0u))
2540 {
2541 temp[i] = static_cast<std::uint32_t>(uu % static_cast<unsigned long long>(cpp_dec_float_elem_mask));
2542 uu = static_cast<unsigned long long>(uu / static_cast<unsigned long long>(cpp_dec_float_elem_mask));
2543 ++i;
2544 }
2545
2546 if (i > static_cast<std::size_t>(1u))
2547 {
2548 exp += static_cast<exponent_type>((i - 1u) * static_cast<std::size_t>(cpp_dec_float_elem_digits10));
2549 }
2550
2551 std::reverse(temp, temp + i);
2552 std::copy(temp, temp + (std::min)(i, static_cast<std::size_t>(cpp_dec_float_elem_number)), data.begin());
2553 }
2554
2555 template <unsigned Digits10, class ExponentType, class Allocator>
2556 template <typename InputIteratorTypeLeft, typename InputIteratorTypeRight>
2557 int cpp_dec_float<Digits10, ExponentType, Allocator>::compare_ranges(InputIteratorTypeLeft a,
2558 InputIteratorTypeRight b,
2559 const std::uint32_t count)
2560 {
2561 using local_iterator_left_type = InputIteratorTypeLeft;
2562 using local_iterator_right_type = InputIteratorTypeRight;
2563
2564 local_iterator_left_type begin_a(a);
2565 local_iterator_left_type end_a (a + static_cast<typename std::iterator_traits<local_iterator_left_type >::difference_type>(count));
2566 local_iterator_right_type begin_b(b);
2567 local_iterator_right_type end_b (b + static_cast<typename std::iterator_traits<local_iterator_right_type>::difference_type>(count));
2568
2569 const auto mismatch_pair = std::mismatch(begin_a, end_a, begin_b);
2570
2571 int n_return;
2572
2573 if((mismatch_pair.first != end_a) || (mismatch_pair.second != end_b))
2574 {
2575 const typename std::iterator_traits<local_iterator_left_type >::value_type left = *mismatch_pair.first;
2576 const typename std::iterator_traits<local_iterator_right_type>::value_type right = *mismatch_pair.second;
2577
2578 n_return = ((left > right) ? 1 : -1);
2579 }
2580 else
2581 {
2582 n_return = 0;
2583 }
2584
2585 return n_return;
2586 }
2587
2588 template <unsigned Digits10, class ExponentType, class Allocator>
2589 std::uint32_t cpp_dec_float<Digits10, ExponentType, Allocator>::eval_add_n( std::uint32_t* r,
2590 const std::uint32_t* u,
2591 const std::uint32_t* v,
2592 const std::int32_t count)
2593 {
2594
2595 std::uint_fast8_t carry = static_cast<std::uint_fast8_t>(0U);
2596
2597 for(std::int32_t j = static_cast<std::int32_t>(count - static_cast<std::int32_t>(1)); j >= static_cast<std::int32_t>(0); --j)
2598 {
2599 const std::uint32_t t = static_cast<std::uint32_t>(static_cast<std::uint32_t>(u[j] + v[j]) + carry);
2600
2601 carry = ((t >= static_cast<std::uint32_t>(cpp_dec_float_elem_mask)) ? static_cast<std::uint_fast8_t>(1U)
2602 : static_cast<std::uint_fast8_t>(0U));
2603
2604 r[j] = static_cast<std::uint32_t>(t - ((carry != 0U) ? static_cast<std::uint32_t>(cpp_dec_float_elem_mask)
2605 : static_cast<std::uint32_t>(0U)));
2606 }
2607
2608 return static_cast<std::uint32_t>(carry);
2609 }
2610
2611 template <unsigned Digits10, class ExponentType, class Allocator>
2612 std::uint32_t cpp_dec_float<Digits10, ExponentType, Allocator>::eval_subtract_n( std::uint32_t* r,
2613 const std::uint32_t* u,
2614 const std::uint32_t* v,
2615 const std::int32_t count)
2616 {
2617
2618 std::int_fast8_t borrow = static_cast<std::int_fast8_t>(0);
2619
2620 for(std::uint32_t j = static_cast<std::uint32_t>(count - static_cast<std::int32_t>(1)); static_cast<std::int32_t>(j) >= static_cast<std::int32_t>(0); --j)
2621 {
2622 std::int32_t t = static_cast<std::int32_t>( static_cast<std::int32_t>(u[j])
2623 - static_cast<std::int32_t>(v[j])) - borrow;
2624
2625
2626 if(t < 0)
2627 {
2628
2629 t += static_cast<std::int32_t>(cpp_dec_float_elem_mask);
2630 borrow = static_cast<std::int_fast8_t>(1);
2631 }
2632 else
2633 {
2634 borrow = static_cast<std::int_fast8_t>(0);
2635 }
2636
2637 r[j] = static_cast<std::uint32_t>(t);
2638 }
2639
2640 return static_cast<std::uint32_t>(borrow);
2641 }
2642
2643 template <unsigned Digits10, class ExponentType, class Allocator>
2644 void cpp_dec_float<Digits10, ExponentType, Allocator>::eval_multiply_n_by_n_to_2n( std::uint32_t* r,
2645 const std::uint32_t* a,
2646 const std::uint32_t* b,
2647 const std::uint32_t count)
2648 {
2649 using local_limb_type = std::uint32_t;
2650
2651 using local_double_limb_type = std::uint64_t;
2652
2653 using local_reverse_iterator_type = std::reverse_iterator<local_limb_type*>;
2654
2655 local_reverse_iterator_type ir(r + (count * 2));
2656
2657 local_double_limb_type carry = 0U;
2658
2659 for(std::int32_t j = static_cast<std::int32_t>(count - 1); j >= static_cast<std::int32_t>(1); --j)
2660 {
2661 local_double_limb_type sum = carry;
2662
2663 for(std::int32_t i = static_cast<std::int32_t>(count - 1); i >= j; --i)
2664 {
2665 sum += local_double_limb_type(
2666 local_double_limb_type(a[i]) * b[ static_cast<std::int32_t>(count - 1)
2667 - static_cast<std::int32_t>(i - j)]);
2668 }
2669
2670 carry = static_cast<local_double_limb_type>(sum / static_cast<local_limb_type> (cpp_dec_float_elem_mask));
2671 *ir++ = static_cast<local_limb_type> (sum - static_cast<local_double_limb_type>(static_cast<local_double_limb_type>(carry) * static_cast<local_limb_type>(cpp_dec_float_elem_mask)));
2672 }
2673
2674 for(std::int32_t j = static_cast<std::int32_t>(count - 1); j >= static_cast<std::int32_t>(0); --j)
2675 {
2676 local_double_limb_type sum = carry;
2677
2678 for(std::int32_t i = j; i >= static_cast<std::int32_t>(0); --i)
2679 {
2680 sum += static_cast<local_double_limb_type>(a[j - i] * static_cast<local_double_limb_type>(b[i]));
2681 }
2682
2683 carry = static_cast<local_double_limb_type>(sum / static_cast<local_limb_type>(cpp_dec_float_elem_mask));
2684 *ir++ = static_cast<local_limb_type> (sum - static_cast<local_double_limb_type>(static_cast<local_double_limb_type>(carry) * static_cast<local_limb_type>(cpp_dec_float_elem_mask)));
2685 }
2686
2687 *ir = static_cast<local_limb_type>(carry);
2688 }
2689
2690 template <unsigned Digits10, class ExponentType, class Allocator>
2691 std::uint32_t cpp_dec_float<Digits10, ExponentType, Allocator>::mul_loop_n(std::uint32_t* const u, std::uint32_t n, const std::int32_t p)
2692 {
2693 std::uint64_t carry = static_cast<std::uint64_t>(0u);
2694
2695
2696 for (std::int32_t j = p - 1; j >= static_cast<std::int32_t>(0); j--)
2697 {
2698 const std::uint64_t t = static_cast<std::uint64_t>(carry + static_cast<std::uint64_t>(u[j] * static_cast<std::uint64_t>(n)));
2699 carry = static_cast<std::uint64_t>(t / static_cast<std::uint32_t>(cpp_dec_float_elem_mask));
2700 u[j] = static_cast<std::uint32_t>(t - static_cast<std::uint64_t>(static_cast<std::uint32_t>(cpp_dec_float_elem_mask) * static_cast<std::uint64_t>(carry)));
2701 }
2702
2703 return static_cast<std::uint32_t>(carry);
2704 }
2705
2706 template <unsigned Digits10, class ExponentType, class Allocator>
2707 std::uint32_t cpp_dec_float<Digits10, ExponentType, Allocator>::div_loop_n(std::uint32_t* const u, std::uint32_t n, const std::int32_t p)
2708 {
2709 std::uint64_t prev = static_cast<std::uint64_t>(0u);
2710
2711 for (std::int32_t j = static_cast<std::int32_t>(0); j < p; j++)
2712 {
2713 const std::uint64_t t = static_cast<std::uint64_t>(u[j] + static_cast<std::uint64_t>(prev * static_cast<std::uint32_t>(cpp_dec_float_elem_mask)));
2714 u[j] = static_cast<std::uint32_t>(t / n);
2715 prev = static_cast<std::uint64_t>(t - static_cast<std::uint64_t>(n * static_cast<std::uint64_t>(u[j])));
2716 }
2717
2718 return static_cast<std::uint32_t>(prev);
2719 }
2720
2721 template <unsigned Digits10, class ExponentType, class Allocator>
2722 void cpp_dec_float<Digits10, ExponentType, Allocator>::eval_multiply_kara_propagate_carry(std::uint32_t* t, const std::uint32_t n, const std::uint32_t carry)
2723 {
2724 std::uint_fast8_t carry_out = ((carry != 0U) ? static_cast<std::uint_fast8_t>(1U)
2725 : static_cast<std::uint_fast8_t>(0U));
2726
2727 using local_reverse_iterator_type = std::reverse_iterator<std::uint32_t*>;
2728
2729 local_reverse_iterator_type ri_t (t + n);
2730 local_reverse_iterator_type rend_t(t);
2731
2732 while((carry_out != 0U) && (ri_t != rend_t))
2733 {
2734 const std::uint64_t tt = *ri_t + carry_out;
2735
2736 carry_out = ((tt >= static_cast<std::uint32_t>(cpp_dec_float_elem_mask)) ? static_cast<std::uint_fast8_t>(1U)
2737 : static_cast<std::uint_fast8_t>(0U));
2738
2739 *ri_t++ = static_cast<std::uint32_t>(tt - ((carry_out != 0U) ? static_cast<std::uint32_t>(cpp_dec_float_elem_mask)
2740 : static_cast<std::uint32_t>(0U)));
2741 }
2742 }
2743
2744 template <unsigned Digits10, class ExponentType, class Allocator>
2745 void cpp_dec_float<Digits10, ExponentType, Allocator>::eval_multiply_kara_propagate_borrow(std::uint32_t* t, const std::uint32_t n, const bool has_borrow)
2746 {
2747 std::int_fast8_t borrow = (has_borrow ? static_cast<std::int_fast8_t>(1)
2748 : static_cast<std::int_fast8_t>(0));
2749
2750 using local_reverse_iterator_type = std::reverse_iterator<std::uint32_t*>;
2751
2752 local_reverse_iterator_type ri_t (t + n);
2753 local_reverse_iterator_type rend_t(t);
2754
2755 while((borrow != 0U) && (ri_t != rend_t))
2756 {
2757 std::int32_t tt = static_cast<std::int32_t>(static_cast<std::int32_t>(*ri_t) - borrow);
2758
2759
2760 if(tt < 0)
2761 {
2762
2763 tt += static_cast<std::int32_t>(cpp_dec_float_elem_mask);
2764 borrow = static_cast<int_fast8_t>(1);
2765 }
2766 else
2767 {
2768 borrow = static_cast<int_fast8_t>(0);
2769 }
2770
2771 *ri_t++ = static_cast<std::uint32_t>(tt);
2772 }
2773 }
2774
2775 template <unsigned Digits10, class ExponentType, class Allocator>
2776 void cpp_dec_float<Digits10, ExponentType, Allocator>::eval_multiply_kara_n_by_n_to_2n( std::uint32_t* r,
2777 const std::uint32_t* a,
2778 const std::uint32_t* b,
2779 const std::uint32_t n,
2780 std::uint32_t* t)
2781 {
2782 if(n <= 32U)
2783 {
2784 static_cast<void>(t);
2785
2786 eval_multiply_n_by_n_to_2n(r, a, b, n);
2787 }
2788 else
2789 {
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823 const std::uint_fast32_t nh = n / 2U;
2824
2825 const std::uint32_t* a0 = a + nh;
2826 const std::uint32_t* a1 = a + 0U;
2827
2828 const std::uint32_t* b0 = b + nh;
2829 const std::uint32_t* b1 = b + 0U;
2830
2831 std::uint32_t* r0 = r + 0U;
2832 std::uint32_t* r1 = r + nh;
2833 std::uint32_t* r2 = r + n;
2834
2835 std::uint32_t* t0 = t + 0U;
2836 std::uint32_t* t1 = t + nh;
2837 std::uint32_t* t2 = t + n;
2838 std::uint32_t* t4 = t + (n + n);
2839
2840
2841 eval_multiply_kara_n_by_n_to_2n(r0, a1, b1, static_cast<std::uint32_t>(nh), t);
2842 eval_multiply_kara_n_by_n_to_2n(r2, a0, b0, static_cast<std::uint32_t>(nh), t);
2843 std::copy(r0, r0 + (2U * n), t0);
2844
2845
2846 std::uint32_t carry;
2847 carry = eval_add_n(r1, r1, t0, static_cast<std::int32_t>(n));
2848 eval_multiply_kara_propagate_carry(r0, static_cast<std::uint32_t>(nh), carry);
2849 carry = eval_add_n(r1, r1, t2, static_cast<std::int32_t>(n));
2850 eval_multiply_kara_propagate_carry(r0, static_cast<std::uint32_t>(nh), carry);
2851
2852
2853 const int cmp_result_a1a0 = compare_ranges(a1, a0, static_cast<std::uint32_t>(nh));
2854
2855 if(cmp_result_a1a0 == 1)
2856 static_cast<void>(eval_subtract_n(t0, a1, a0, static_cast<std::int32_t>(nh)));
2857 else if(cmp_result_a1a0 == -1)
2858 static_cast<void>(eval_subtract_n(t0, a0, a1, static_cast<std::int32_t>(nh)));
2859
2860
2861 const int cmp_result_b0b1 = compare_ranges(b0, b1, static_cast<std::uint32_t>(nh));
2862
2863 if(cmp_result_b0b1 == 1)
2864 static_cast<void>(eval_subtract_n(t1, b0, b1, static_cast<std::int32_t>(nh)));
2865 else if(cmp_result_b0b1 == -1)
2866 static_cast<void>(eval_subtract_n(t1, b1, b0, static_cast<std::int32_t>(nh)));
2867
2868
2869 eval_multiply_kara_n_by_n_to_2n(t2, t0, t1, static_cast<std::uint32_t>(nh), t4);
2870
2871
2872 if((cmp_result_a1a0 * cmp_result_b0b1) == 1)
2873 {
2874 carry = eval_add_n(r1, r1, t2, static_cast<std::int32_t>(n));
2875
2876 eval_multiply_kara_propagate_carry(r0, static_cast<std::uint32_t>(nh), carry);
2877 }
2878 else if((cmp_result_a1a0 * cmp_result_b0b1) == -1)
2879 {
2880 const bool has_borrow = eval_subtract_n(r1, r1, t2, static_cast<std::int32_t>(n));
2881
2882 eval_multiply_kara_propagate_borrow(r0, static_cast<std::uint32_t>(nh), has_borrow);
2883 }
2884 }
2885 }
2886
2887 template <unsigned Digits10, class ExponentType, class Allocator>
2888 cpp_dec_float<Digits10, ExponentType, Allocator> cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(const long long p)
2889 {
2890 static const std::array<cpp_dec_float<Digits10, ExponentType, Allocator>, 256u> local_pow2_data =
2891 {{
2892 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 29u, 38735877u, 5571876u, 99218413u, 43055614u, 19454666u, 38919302u, 18803771u, 87926569u, 60431486u, 36817932u, 12890625u }, -40 ),
2893 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 58u, 77471754u, 11143753u, 98436826u, 86111228u, 38909332u, 77838604u, 37607543u, 75853139u, 20862972u, 73635864u, 25781250u }, -40 ),
2894 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 117u, 54943508u, 22287507u, 96873653u, 72222456u, 77818665u, 55677208u, 75215087u, 51706278u, 41725945u, 47271728u, 51562500u }, -40 ),
2895 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 235u, 9887016u, 44575015u, 93747307u, 44444913u, 55637331u, 11354417u, 50430175u, 3412556u, 83451890u, 94543457u, 3125000u }, -40 ),
2896 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 470u, 19774032u, 89150031u, 87494614u, 88889827u, 11274662u, 22708835u, 860350u, 6825113u, 66903781u, 89086914u, 6250000u }, -40 ),
2897 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 940u, 39548065u, 78300063u, 74989229u, 77779654u, 22549324u, 45417670u, 1720700u, 13650227u, 33807563u, 78173828u, 12500000u }, -40 ),
2898 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1880u, 79096131u, 56600127u, 49978459u, 55559308u, 45098648u, 90835340u, 3441400u, 27300454u, 67615127u, 56347656u, 25000000u }, -40 ),
2899 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3761u, 58192263u, 13200254u, 99956919u, 11118616u, 90197297u, 81670680u, 6882800u, 54600909u, 35230255u, 12695312u, 50000000u }, -40 ),
2900 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 7523u, 16384526u, 26400509u, 99913838u, 22237233u, 80394595u, 63341360u, 13765601u, 9201818u, 70460510u, 25390625u }, -40 ),
2901 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 15046u, 32769052u, 52801019u, 99827676u, 44474467u, 60789191u, 26682720u, 27531202u, 18403637u, 40921020u, 50781250u }, -40 ),
2902 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 30092u, 65538105u, 5602039u, 99655352u, 88948935u, 21578382u, 53365440u, 55062404u, 36807274u, 81842041u, 1562500u }, -40 ),
2903 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 60185u, 31076210u, 11204079u, 99310705u, 77897870u, 43156765u, 6730881u, 10124808u, 73614549u, 63684082u, 3125000u }, -40 ),
2904 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 120370u, 62152420u, 22408159u, 98621411u, 55795740u, 86313530u, 13461762u, 20249617u, 47229099u, 27368164u, 6250000u }, -40 ),
2905 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 240741u, 24304840u, 44816319u, 97242823u, 11591481u, 72627060u, 26923524u, 40499234u, 94458198u, 54736328u, 12500000u }, -40 ),
2906 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 481482u, 48609680u, 89632639u, 94485646u, 23182963u, 45254120u, 53847048u, 80998469u, 88916397u, 9472656u, 25000000u }, -40 ),
2907 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 962964u, 97219361u, 79265279u, 88971292u, 46365926u, 90508241u, 7694097u, 61996939u, 77832794u, 18945312u, 50000000u }, -40 ),
2908 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1925929u, 94438723u, 58530559u, 77942584u, 92731853u, 81016482u, 15388195u, 23993879u, 55665588u, 37890625u }, -40 ),
2909 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3851859u, 88877447u, 17061119u, 55885169u, 85463707u, 62032964u, 30776390u, 47987759u, 11331176u, 75781250u }, -40 ),
2910 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 7703719u, 77754894u, 34122239u, 11770339u, 70927415u, 24065928u, 61552780u, 95975518u, 22662353u, 51562500u }, -40 ),
2911 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 15407439u, 55509788u, 68244478u, 23540679u, 41854830u, 48131857u, 23105561u, 91951036u, 45324707u, 3125000u }, -40 ),
2912 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 30814879u, 11019577u, 36488956u, 47081358u, 83709660u, 96263714u, 46211123u, 83902072u, 90649414u, 6250000u }, -40 ),
2913 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 61629758u, 22039154u, 72977912u, 94162717u, 67419321u, 92527428u, 92422247u, 67804145u, 81298828u, 12500000u }, -40 ),
2914 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1u, 23259516u, 44078309u, 45955825u, 88325435u, 34838643u, 85054857u, 84844495u, 35608291u, 62597656u, 25000000u }, -32 ),
2915 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2u, 46519032u, 88156618u, 91911651u, 76650870u, 69677287u, 70109715u, 69688990u, 71216583u, 25195312u, 50000000u }, -32 ),
2916 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 4u, 93038065u, 76313237u, 83823303u, 53301741u, 39354575u, 40219431u, 39377981u, 42433166u, 50390625u }, -32 ),
2917 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 9u, 86076131u, 52626475u, 67646607u, 6603482u, 78709150u, 80438862u, 78755962u, 84866333u, 781250u }, -32 ),
2918 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 19u, 72152263u, 5252951u, 35293214u, 13206965u, 57418301u, 60877725u, 57511925u, 69732666u, 1562500u }, -32 ),
2919 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 39u, 44304526u, 10505902u, 70586428u, 26413931u, 14836603u, 21755451u, 15023851u, 39465332u, 3125000u }, -32 ),
2920 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 78u, 88609052u, 21011805u, 41172856u, 52827862u, 29673206u, 43510902u, 30047702u, 78930664u, 6250000u }, -32 ),
2921 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 157u, 77218104u, 42023610u, 82345713u, 5655724u, 59346412u, 87021804u, 60095405u, 57861328u, 12500000u }, -32 ),
2922 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 315u, 54436208u, 84047221u, 64691426u, 11311449u, 18692825u, 74043609u, 20190811u, 15722656u, 25000000u }, -32 ),
2923 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 631u, 8872417u, 68094443u, 29382852u, 22622898u, 37385651u, 48087218u, 40381622u, 31445312u, 50000000u }, -32 ),
2924 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1262u, 17744835u, 36188886u, 58765704u, 45245796u, 74771302u, 96174436u, 80763244u, 62890625u }, -32 ),
2925 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2524u, 35489670u, 72377773u, 17531408u, 90491593u, 49542605u, 92348873u, 61526489u, 25781250u }, -32 ),
2926 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 5048u, 70979341u, 44755546u, 35062817u, 80983186u, 99085211u, 84697747u, 23052978u, 51562500u }, -32 ),
2927 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 10097u, 41958682u, 89511092u, 70125635u, 61966373u, 98170423u, 69395494u, 46105957u, 3125000u }, -32 ),
2928 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 20194u, 83917365u, 79022185u, 40251271u, 23932747u, 96340847u, 38790988u, 92211914u, 6250000u }, -32 ),
2929 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 40389u, 67834731u, 58044370u, 80502542u, 47865495u, 92681694u, 77581977u, 84423828u, 12500000u }, -32 ),
2930 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 80779u, 35669463u, 16088741u, 61005084u, 95730991u, 85363389u, 55163955u, 68847656u, 25000000u }, -32 ),
2931 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 161558u, 71338926u, 32177483u, 22010169u, 91461983u, 70726779u, 10327911u, 37695312u, 50000000u }, -32 ),
2932 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 323117u, 42677852u, 64354966u, 44020339u, 82923967u, 41453558u, 20655822u, 75390625u }, -32 ),
2933 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 646234u, 85355705u, 28709932u, 88040679u, 65847934u, 82907116u, 41311645u, 50781250u }, -32 ),
2934 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1292469u, 70711410u, 57419865u, 76081359u, 31695869u, 65814232u, 82623291u, 1562500u }, -32 ),
2935 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2584939u, 41422821u, 14839731u, 52162718u, 63391739u, 31628465u, 65246582u, 3125000u }, -32 ),
2936 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 5169878u, 82845642u, 29679463u, 4325437u, 26783478u, 63256931u, 30493164u, 6250000u }, -32 ),
2937 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 10339757u, 65691284u, 59358926u, 8650874u, 53566957u, 26513862u, 60986328u, 12500000u }, -32 ),
2938 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 20679515u, 31382569u, 18717852u, 17301749u, 7133914u, 53027725u, 21972656u, 25000000u }, -32 ),
2939 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 41359030u, 62765138u, 37435704u, 34603498u, 14267829u, 6055450u, 43945312u, 50000000u }, -32 ),
2940 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 82718061u, 25530276u, 74871408u, 69206996u, 28535658u, 12110900u, 87890625u }, -32 ),
2941 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1u, 65436122u, 51060553u, 49742817u, 38413992u, 57071316u, 24221801u, 75781250u }, -24 ),
2942 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3u, 30872245u, 2121106u, 99485634u, 76827985u, 14142632u, 48443603u, 51562500u }, -24 ),
2943 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 6u, 61744490u, 4242213u, 98971269u, 53655970u, 28285264u, 96887207u, 3125000u }, -24 ),
2944 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 13u, 23488980u, 8484427u, 97942539u, 7311940u, 56570529u, 93774414u, 6250000u }, -24 ),
2945 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 26u, 46977960u, 16968855u, 95885078u, 14623881u, 13141059u, 87548828u, 12500000u }, -24 ),
2946 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 52u, 93955920u, 33937711u, 91770156u, 29247762u, 26282119u, 75097656u, 25000000u }, -24 ),
2947 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 105u, 87911840u, 67875423u, 83540312u, 58495524u, 52564239u, 50195312u, 50000000u }, -24 ),
2948 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 211u, 75823681u, 35750847u, 67080625u, 16991049u, 5128479u, 390625u }, -24 ),
2949 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 423u, 51647362u, 71501695u, 34161250u, 33982098u, 10256958u, 781250u }, -24 ),
2950 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 847u, 3294725u, 43003390u, 68322500u, 67964196u, 20513916u, 1562500u }, -24 ),
2951 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1694u, 6589450u, 86006781u, 36645001u, 35928392u, 41027832u, 3125000u }, -24 ),
2952 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3388u, 13178901u, 72013562u, 73290002u, 71856784u, 82055664u, 6250000u }, -24 ),
2953 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 6776u, 26357803u, 44027125u, 46580005u, 43713569u, 64111328u, 12500000u }, -24 ),
2954 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 13552u, 52715606u, 88054250u, 93160010u, 87427139u, 28222656u, 25000000u }, -24 ),
2955 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 27105u, 5431213u, 76108501u, 86320021u, 74854278u, 56445312u, 50000000u }, -24 ),
2956 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 54210u, 10862427u, 52217003u, 72640043u, 49708557u, 12890625u }, -24 ),
2957 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 108420u, 21724855u, 4434007u, 45280086u, 99417114u, 25781250u }, -24 ),
2958 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 216840u, 43449710u, 8868014u, 90560173u, 98834228u, 51562500u }, -24 ),
2959 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 433680u, 86899420u, 17736029u, 81120347u, 97668457u, 3125000u }, -24 ),
2960 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 867361u, 73798840u, 35472059u, 62240695u, 95336914u, 6250000u }, -24 ),
2961 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1734723u, 47597680u, 70944119u, 24481391u, 90673828u, 12500000u }, -24 ),
2962 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3469446u, 95195361u, 41888238u, 48962783u, 81347656u, 25000000u }, -24 ),
2963 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 6938893u, 90390722u, 83776476u, 97925567u, 62695312u, 50000000u }, -24 ),
2964 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 13877787u, 80781445u, 67552953u, 95851135u, 25390625u }, -24 ),
2965 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 27755575u, 61562891u, 35105907u, 91702270u, 50781250u }, -24 ),
2966 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 55511151u, 23125782u, 70211815u, 83404541u, 1562500u }, -24 ),
2967 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1u, 11022302u, 46251565u, 40423631u, 66809082u, 3125000u }, -16 ),
2968 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2u, 22044604u, 92503130u, 80847263u, 33618164u, 6250000u }, -16 ),
2969 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 4u, 44089209u, 85006261u, 61694526u, 67236328u, 12500000u }, -16 ),
2970 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 8u, 88178419u, 70012523u, 23389053u, 34472656u, 25000000u }, -16 ),
2971 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 17u, 76356839u, 40025046u, 46778106u, 68945312u, 50000000u }, -16 ),
2972 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 35u, 52713678u, 80050092u, 93556213u, 37890625u }, -16 ),
2973 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 71u, 5427357u, 60100185u, 87112426u, 75781250u }, -16 ),
2974 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 142u, 10854715u, 20200371u, 74224853u, 51562500u }, -16 ),
2975 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 284u, 21709430u, 40400743u, 48449707u, 3125000u }, -16 ),
2976 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 568u, 43418860u, 80801486u, 96899414u, 6250000u }, -16 ),
2977 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1136u, 86837721u, 61602973u, 93798828u, 12500000u }, -16 ),
2978 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2273u, 73675443u, 23205947u, 87597656u, 25000000u }, -16 ),
2979 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 4547u, 47350886u, 46411895u, 75195312u, 50000000u }, -16 ),
2980 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 9094u, 94701772u, 92823791u, 50390625u }, -16 ),
2981 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 18189u, 89403545u, 85647583u, 781250u }, -16 ),
2982 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 36379u, 78807091u, 71295166u, 1562500u }, -16 ),
2983 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 72759u, 57614183u, 42590332u, 3125000u }, -16 ),
2984 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 145519u, 15228366u, 85180664u, 6250000u }, -16 ),
2985 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 291038u, 30456733u, 70361328u, 12500000u }, -16 ),
2986 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 582076u, 60913467u, 40722656u, 25000000u }, -16 ),
2987 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1164153u, 21826934u, 81445312u, 50000000u }, -16 ),
2988 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2328306u, 43653869u, 62890625u }, -16 ),
2989 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 4656612u, 87307739u, 25781250u }, -16 ),
2990 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 9313225u, 74615478u, 51562500u }, -16 ),
2991 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 18626451u, 49230957u, 3125000u }, -16 ),
2992 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 37252902u, 98461914u, 6250000u }, -16 ),
2993 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 74505805u, 96923828u, 12500000u }, -16 ),
2994 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1u, 49011611u, 93847656u, 25000000u }, -8 ),
2995 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2u, 98023223u, 87695312u, 50000000u }, -8 ),
2996 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 5u, 96046447u, 75390625u }, -8 ),
2997 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 11u, 92092895u, 50781250u }, -8 ),
2998 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 23u, 84185791u, 1562500u }, -8 ),
2999 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 47u, 68371582u, 3125000u }, -8 ),
3000 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 95u, 36743164u, 6250000u }, -8 ),
3001 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 190u, 73486328u, 12500000u }, -8 ),
3002 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 381u, 46972656u, 25000000u }, -8 ),
3003 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 762u, 93945312u, 50000000u }, -8 ),
3004 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1525u, 87890625u }, -8 ),
3005 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3051u, 75781250u }, -8 ),
3006 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 6103u, 51562500u }, -8 ),
3007 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 12207u, 3125000u }, -8 ),
3008 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 24414u, 6250000u }, -8 ),
3009 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 48828u, 12500000u }, -8 ),
3010 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 97656u, 25000000u }, -8 ),
3011 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 195312u, 50000000u }, -8 ),
3012 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 390625u }, -8 ),
3013 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 781250u }, -8 ),
3014 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1562500u }, -8 ),
3015 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3125000u }, -8 ),
3016 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 6250000u }, -8 ),
3017 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 12500000u }, -8 ),
3018 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 25000000u }, -8 ),
3019 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 50000000u }, -8 ),
3020 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1u }, 0 ),
3021 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2u }, 0 ),
3022 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 4u }, 0 ),
3023 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 8u }, 0 ),
3024 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 16u }, 0 ),
3025 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 32u }, 0 ),
3026 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 64u }, 0 ),
3027 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 128u }, 0 ),
3028 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 256u }, 0 ),
3029 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 512u }, 0 ),
3030 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1024u }, 0 ),
3031 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2048u }, 0 ),
3032 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 4096u }, 0 ),
3033 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 8192u }, 0 ),
3034 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 16384u }, 0 ),
3035 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 32768u }, 0 ),
3036 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 65536u }, 0 ),
3037 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 131072u }, 0 ),
3038 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 262144u }, 0 ),
3039 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 524288u }, 0 ),
3040 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1048576u }, 0 ),
3041 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2097152u }, 0 ),
3042 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 4194304u }, 0 ),
3043 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 8388608u }, 0 ),
3044 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 16777216u }, 0 ),
3045 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 33554432u }, 0 ),
3046 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 67108864u }, 0 ),
3047 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1u, 34217728u }, 8 ),
3048 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2u, 68435456u }, 8 ),
3049 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 5u, 36870912u }, 8 ),
3050 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 10u, 73741824u }, 8 ),
3051 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 21u, 47483648u }, 8 ),
3052 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 42u, 94967296u }, 8 ),
3053 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 85u, 89934592u }, 8 ),
3054 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 171u, 79869184u }, 8 ),
3055 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 343u, 59738368u }, 8 ),
3056 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 687u, 19476736u }, 8 ),
3057 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1374u, 38953472u }, 8 ),
3058 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2748u, 77906944u }, 8 ),
3059 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 5497u, 55813888u }, 8 ),
3060 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 10995u, 11627776u }, 8 ),
3061 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 21990u, 23255552u }, 8 ),
3062 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 43980u, 46511104u }, 8 ),
3063 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 87960u, 93022208u }, 8 ),
3064 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 175921u, 86044416u }, 8 ),
3065 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 351843u, 72088832u }, 8 ),
3066 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 703687u, 44177664u }, 8 ),
3067 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1407374u, 88355328u }, 8 ),
3068 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2814749u, 76710656u }, 8 ),
3069 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 5629499u, 53421312u }, 8 ),
3070 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 11258999u, 6842624u }, 8 ),
3071 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 22517998u, 13685248u }, 8 ),
3072 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 45035996u, 27370496u }, 8 ),
3073 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 90071992u, 54740992u }, 8 ),
3074 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1u, 80143985u, 9481984u }, 16 ),
3075 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3u, 60287970u, 18963968u }, 16 ),
3076 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 7u, 20575940u, 37927936u }, 16 ),
3077 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 14u, 41151880u, 75855872u }, 16 ),
3078 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 28u, 82303761u, 51711744u }, 16 ),
3079 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 57u, 64607523u, 3423488u }, 16 ),
3080 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 115u, 29215046u, 6846976u }, 16 ),
3081 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 230u, 58430092u, 13693952u }, 16 ),
3082 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 461u, 16860184u, 27387904u }, 16 ),
3083 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 922u, 33720368u, 54775808u }, 16 ),
3084 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1844u, 67440737u, 9551616u }, 16 ),
3085 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3689u, 34881474u, 19103232u }, 16 ),
3086 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 7378u, 69762948u, 38206464u }, 16 ),
3087 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 14757u, 39525896u, 76412928u }, 16 ),
3088 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 29514u, 79051793u, 52825856u }, 16 ),
3089 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 59029u, 58103587u, 5651712u }, 16 ),
3090 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 118059u, 16207174u, 11303424u }, 16 ),
3091 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 236118u, 32414348u, 22606848u }, 16 ),
3092 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 472236u, 64828696u, 45213696u }, 16 ),
3093 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 944473u, 29657392u, 90427392u }, 16 ),
3094 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1888946u, 59314785u, 80854784u }, 16 ),
3095 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3777893u, 18629571u, 61709568u }, 16 ),
3096 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 7555786u, 37259143u, 23419136u }, 16 ),
3097 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 15111572u, 74518286u, 46838272u }, 16 ),
3098 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 30223145u, 49036572u, 93676544u }, 16 ),
3099 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 60446290u, 98073145u, 87353088u }, 16 ),
3100 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1u, 20892581u, 96146291u, 74706176u }, 24 ),
3101 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2u, 41785163u, 92292583u, 49412352u }, 24 ),
3102 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 4u, 83570327u, 84585166u, 98824704u }, 24 ),
3103 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 9u, 67140655u, 69170333u, 97649408u }, 24 ),
3104 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 19u, 34281311u, 38340667u, 95298816u }, 24 ),
3105 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 38u, 68562622u, 76681335u, 90597632u }, 24 ),
3106 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 77u, 37125245u, 53362671u, 81195264u }, 24 ),
3107 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 154u, 74250491u, 6725343u, 62390528u }, 24 ),
3108 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 309u, 48500982u, 13450687u, 24781056u }, 24 ),
3109 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 618u, 97001964u, 26901374u, 49562112u }, 24 ),
3110 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1237u, 94003928u, 53802748u, 99124224u }, 24 ),
3111 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2475u, 88007857u, 7605497u, 98248448u }, 24 ),
3112 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 4951u, 76015714u, 15210995u, 96496896u }, 24 ),
3113 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 9903u, 52031428u, 30421991u, 92993792u }, 24 ),
3114 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 19807u, 4062856u, 60843983u, 85987584u }, 24 ),
3115 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 39614u, 8125713u, 21687967u, 71975168u }, 24 ),
3116 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 79228u, 16251426u, 43375935u, 43950336u }, 24 ),
3117 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 158456u, 32502852u, 86751870u, 87900672u }, 24 ),
3118 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 316912u, 65005705u, 73503741u, 75801344u }, 24 ),
3119 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 633825u, 30011411u, 47007483u, 51602688u }, 24 ),
3120 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1267650u, 60022822u, 94014967u, 3205376u }, 24 ),
3121 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 2535301u, 20045645u, 88029934u, 6410752u }, 24 ),
3122 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 5070602u, 40091291u, 76059868u, 12821504u }, 24 ),
3123 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 10141204u, 80182583u, 52119736u, 25643008u }, 24 ),
3124 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 20282409u, 60365167u, 4239472u, 51286016u }, 24 ),
3125 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 40564819u, 20730334u, 8478945u, 2572032u }, 24 ),
3126 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 81129638u, 41460668u, 16957890u, 5144064u }, 24 ),
3127 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1u, 62259276u, 82921336u, 33915780u, 10288128u }, 32 ),
3128 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3u, 24518553u, 65842672u, 67831560u, 20576256u }, 32 ),
3129 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 6u, 49037107u, 31685345u, 35663120u, 41152512u }, 32 ),
3130 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 12u, 98074214u, 63370690u, 71326240u, 82305024u }, 32 ),
3131 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 25u, 96148429u, 26741381u, 42652481u, 64610048u }, 32 ),
3132 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 51u, 92296858u, 53482762u, 85304963u, 29220096u }, 32 ),
3133 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 103u, 84593717u, 6965525u, 70609926u, 58440192u }, 32 ),
3134 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 207u, 69187434u, 13931051u, 41219853u, 16880384u }, 32 ),
3135 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 415u, 38374868u, 27862102u, 82439706u, 33760768u }, 32 ),
3136 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 830u, 76749736u, 55724205u, 64879412u, 67521536u }, 32 ),
3137 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1661u, 53499473u, 11448411u, 29758825u, 35043072u }, 32 ),
3138 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 3323u, 6998946u, 22896822u, 59517650u, 70086144u }, 32 ),
3139 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 6646u, 13997892u, 45793645u, 19035301u, 40172288u }, 32 ),
3140 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 13292u, 27995784u, 91587290u, 38070602u, 80344576u }, 32 ),
3141 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 26584u, 55991569u, 83174580u, 76141205u, 60689152u }, 32 ),
3142 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 53169u, 11983139u, 66349161u, 52282411u, 21378304u }, 32 ),
3143 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 106338u, 23966279u, 32698323u, 4564822u, 42756608u }, 32 ),
3144 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 212676u, 47932558u, 65396646u, 9129644u, 85513216u }, 32 ),
3145 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 425352u, 95865117u, 30793292u, 18259289u, 71026432u }, 32 ),
3146 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 850705u, 91730234u, 61586584u, 36518579u, 42052864u }, 32 ),
3147 cpp_dec_float<Digits10, ExponentType, Allocator>::from_lst( { 1701411u, 83460469u, 23173168u, 73037158u, 84105728u }, 32 ),
3148 }};
3149
3150 cpp_dec_float<Digits10, ExponentType, Allocator> t;
3151
3152 if(p < -128L)
3153 default_ops::detail::pow_imp(t, cpp_dec_float<Digits10, ExponentType, Allocator>::half(), static_cast<unsigned long long>(-p), std::integral_constant<bool, false>());
3154 else if ((p >= -128L) && (p <= 127L))
3155 t = local_pow2_data[std::size_t(p + 128)];
3156 else
3157 default_ops::detail::pow_imp(t, cpp_dec_float<Digits10, ExponentType, Allocator>::two(), static_cast<unsigned long long>(p), std::integral_constant<bool, false>());
3158
3159 return t;
3160 }
3161
3162 template <unsigned Digits10, class ExponentType, class Allocator>
3163 inline void eval_add(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& o)
3164 {
3165 result += o;
3166 }
3167 template <unsigned Digits10, class ExponentType, class Allocator>
3168 inline void eval_subtract(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& o)
3169 {
3170 result -= o;
3171 }
3172 template <unsigned Digits10, class ExponentType, class Allocator>
3173 inline void eval_multiply(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& o)
3174 {
3175 result *= o;
3176 }
3177 template <unsigned Digits10, class ExponentType, class Allocator>
3178 inline void eval_divide(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& o)
3179 {
3180 result /= o;
3181 }
3182
3183 template <unsigned Digits10, class ExponentType, class Allocator>
3184 inline void eval_add(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const unsigned long long& o)
3185 {
3186 result.add_unsigned_long_long(o);
3187 }
3188 template <unsigned Digits10, class ExponentType, class Allocator>
3189 inline void eval_subtract(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const unsigned long long& o)
3190 {
3191 result.sub_unsigned_long_long(o);
3192 }
3193 template <unsigned Digits10, class ExponentType, class Allocator>
3194 inline void eval_multiply(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const unsigned long long& o)
3195 {
3196 result.mul_unsigned_long_long(o);
3197 }
3198 template <unsigned Digits10, class ExponentType, class Allocator>
3199 inline void eval_divide(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const unsigned long long& o)
3200 {
3201 result.div_unsigned_long_long(o);
3202 }
3203
3204 template <unsigned Digits10, class ExponentType, class Allocator>
3205 inline void eval_add(cpp_dec_float<Digits10, ExponentType, Allocator>& result, long long o)
3206 {
3207 if (o < 0)
3208 result.sub_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(o));
3209 else
3210 {
3211 using local_ulonglong_type = typename boost::multiprecision::detail::make_unsigned<long long>::type;
3212
3213 result.add_unsigned_long_long(static_cast<local_ulonglong_type>(o));
3214 }
3215 }
3216 template <unsigned Digits10, class ExponentType, class Allocator>
3217 inline void eval_subtract(cpp_dec_float<Digits10, ExponentType, Allocator>& result, long long o)
3218 {
3219 if (o < 0)
3220 result.add_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(o));
3221 else
3222 {
3223 using local_ulonglong_type = typename boost::multiprecision::detail::make_unsigned<long long>::type;
3224
3225 result.sub_unsigned_long_long(static_cast<local_ulonglong_type>(o));
3226 }
3227 }
3228 template <unsigned Digits10, class ExponentType, class Allocator>
3229 inline void eval_multiply(cpp_dec_float<Digits10, ExponentType, Allocator>& result, long long o)
3230 {
3231 if (o < 0)
3232 {
3233 result.mul_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(o));
3234 result.negate();
3235 }
3236 else
3237 {
3238 using local_ulonglong_type = typename boost::multiprecision::detail::make_unsigned<long long>::type;
3239
3240 result.mul_unsigned_long_long(static_cast<local_ulonglong_type>(o));
3241 }
3242 }
3243 template <unsigned Digits10, class ExponentType, class Allocator>
3244 inline void eval_divide(cpp_dec_float<Digits10, ExponentType, Allocator>& result, long long o)
3245 {
3246 if (o < 0)
3247 {
3248 result.div_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(o));
3249 result.negate();
3250 }
3251 else
3252 {
3253 using local_ulonglong_type = typename boost::multiprecision::detail::make_unsigned<long long>::type;
3254
3255 result.div_unsigned_long_long(static_cast<local_ulonglong_type>(o));
3256 }
3257 }
3258
3259 template <unsigned Digits10, class ExponentType, class Allocator>
3260 inline void eval_convert_to(unsigned long long* result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3261 {
3262 *result = val.extract_unsigned_long_long();
3263 }
3264 template <unsigned Digits10, class ExponentType, class Allocator>
3265 inline void eval_convert_to(long long* result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3266 {
3267 *result = val.extract_signed_long_long();
3268 }
3269 #ifdef BOOST_HAS_INT128
3270 template <unsigned Digits10, class ExponentType, class Allocator>
3271 inline void eval_convert_to(uint128_type* result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3272 {
3273 *result = val.extract_unsigned_int128();
3274 }
3275 template <unsigned Digits10, class ExponentType, class Allocator>
3276 inline void eval_convert_to(int128_type* result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3277 {
3278 *result = val.extract_signed_int128();
3279 }
3280 #endif
3281 template <unsigned Digits10, class ExponentType, class Allocator>
3282 inline void eval_convert_to(long double* result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3283 {
3284 *result = val.extract_long_double();
3285 }
3286 template <unsigned Digits10, class ExponentType, class Allocator>
3287 inline void eval_convert_to(double* result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3288 {
3289 *result = val.extract_double();
3290 }
3291 #if defined(BOOST_HAS_FLOAT128)
3292 template <unsigned Digits10, class ExponentType, class Allocator>
3293 inline void eval_convert_to(float128_type* result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3294 {
3295 *result = float128_procs::strtoflt128(val.str(0, std::ios_base::scientific).c_str(), nullptr);
3296 }
3297 #endif
3298
3299
3300
3301
3302 template <unsigned Digits10, class ExponentType, class Allocator>
3303 inline int eval_fpclassify(const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
3304 {
3305 if ((x.isinf)())
3306 return FP_INFINITE;
3307 if ((x.isnan)())
3308 return FP_NAN;
3309 if (x.iszero())
3310 return FP_ZERO;
3311 return FP_NORMAL;
3312 }
3313
3314 template <unsigned Digits10, class ExponentType, class Allocator>
3315 inline void eval_abs(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
3316 {
3317 result = x;
3318 if (x.isneg())
3319 result.negate();
3320 }
3321
3322 template <unsigned Digits10, class ExponentType, class Allocator>
3323 inline void eval_fabs(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
3324 {
3325 result = x;
3326 if (x.isneg())
3327 result.negate();
3328 }
3329
3330 template <unsigned Digits10, class ExponentType, class Allocator>
3331 inline void eval_sqrt(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
3332 {
3333 result = x;
3334 result.calculate_sqrt();
3335 }
3336
3337 template <unsigned Digits10, class ExponentType, class Allocator>
3338 inline void eval_floor(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
3339 {
3340 result = x;
3341 if (!(x.isfinite)() || x.isint())
3342 {
3343 if ((x.isnan)())
3344 errno = EDOM;
3345 return;
3346 }
3347
3348 if (x.isneg())
3349 result -= cpp_dec_float<Digits10, ExponentType, Allocator>::one();
3350 result = result.extract_integer_part();
3351 }
3352
3353 template <unsigned Digits10, class ExponentType, class Allocator>
3354 inline void eval_ceil(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
3355 {
3356 result = x;
3357 if (!(x.isfinite)() || x.isint())
3358 {
3359 if ((x.isnan)())
3360 errno = EDOM;
3361 return;
3362 }
3363
3364 if (!x.isneg())
3365 result += cpp_dec_float<Digits10, ExponentType, Allocator>::one();
3366 result = result.extract_integer_part();
3367 }
3368
3369 template <unsigned Digits10, class ExponentType, class Allocator>
3370 inline void eval_trunc(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
3371 {
3372 if (x.isint() || !(x.isfinite)())
3373 {
3374 result = x;
3375 if ((x.isnan)())
3376 errno = EDOM;
3377 return;
3378 }
3379 result = x.extract_integer_part();
3380 }
3381
3382 template <unsigned Digits10, class ExponentType, class Allocator>
3383 inline ExponentType eval_ilogb(const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3384 {
3385 if (val.iszero())
3386 return (std::numeric_limits<typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type>::min)();
3387 if ((val.isinf)())
3388 return INT_MAX;
3389 if ((val.isnan)())
3390 #ifdef FP_ILOGBNAN
3391 return FP_ILOGBNAN;
3392 #else
3393 return INT_MAX;
3394 #endif
3395
3396 return val.order();
3397 }
3398 template <unsigned Digits10, class ExponentType, class Allocator, class ArgType>
3399 inline void eval_scalbn(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val, ArgType e_)
3400 {
3401 using default_ops::eval_multiply;
3402 const typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type e = static_cast<typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type>(e_);
3403 cpp_dec_float<Digits10, ExponentType, Allocator> t(1.0, e);
3404 eval_multiply(result, val, t);
3405 }
3406
3407 template <unsigned Digits10, class ExponentType, class Allocator, class ArgType>
3408 inline void eval_ldexp(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x, ArgType e)
3409 {
3410 const long long the_exp = static_cast<long long>(e);
3411
3412 if ((the_exp > (std::numeric_limits<typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type>::max)()) || (the_exp < (std::numeric_limits<typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type>::min)()))
3413 BOOST_MP_THROW_EXCEPTION(std::runtime_error(std::string("Exponent value is out of range.")));
3414
3415 result = x;
3416
3417 if ((the_exp > static_cast<long long>(-std::numeric_limits<long long>::digits)) && (the_exp < static_cast<long long>(0)))
3418 result.div_unsigned_long_long(1ULL << static_cast<long long>(-the_exp));
3419 else if ((the_exp < static_cast<long long>(std::numeric_limits<long long>::digits)) && (the_exp > static_cast<long long>(0)))
3420 result.mul_unsigned_long_long(1ULL << the_exp);
3421 else if (the_exp != static_cast<long long>(0))
3422 {
3423 if ((the_exp < cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp / 2) && (x.order() > 0))
3424 {
3425 long long half_exp = e / 2;
3426 cpp_dec_float<Digits10, ExponentType, Allocator> t = cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(half_exp);
3427 result *= t;
3428 if (2 * half_exp != e)
3429 t *= 2;
3430 result *= t;
3431 }
3432 else
3433 result *= cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(e);
3434 }
3435 }
3436
3437 template <unsigned Digits10, class ExponentType, class Allocator>
3438 inline void eval_frexp(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x, ExponentType* e)
3439 {
3440 result = x;
3441
3442 if (result.iszero() || (result.isinf)() || (result.isnan)())
3443 {
3444 *e = 0;
3445 return;
3446 }
3447
3448 if (result.isneg())
3449 result.negate();
3450
3451 typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type t = result.order();
3452 BOOST_MP_USING_ABS
3453 if (abs(t) < ((std::numeric_limits<typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type>::max)() / 1000))
3454 {
3455 t *= 1000;
3456 t /= 301;
3457 }
3458 else
3459 {
3460 t /= 301;
3461 t *= 1000;
3462 }
3463
3464 result *= cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(-t);
3465
3466 if (result.iszero() || (result.isinf)() || (result.isnan)())
3467 {
3468
3469 result = x;
3470 if (result.isneg())
3471 result.negate();
3472 t /= 2;
3473 result *= cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(-t);
3474 }
3475 BOOST_MP_USING_ABS
3476 if (abs(result.order()) > 5)
3477 {
3478
3479 typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type e2;
3480 cpp_dec_float<Digits10, ExponentType, Allocator> r2;
3481 eval_frexp(r2, result, &e2);
3482
3483 if ((t > 0) && (e2 > 0) && (t > (std::numeric_limits<typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type>::max)() - e2))
3484 BOOST_MP_THROW_EXCEPTION(std::runtime_error("Exponent is too large to be represented as a power of 2."));
3485 if ((t < 0) && (e2 < 0) && (t < (std::numeric_limits<typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type>::min)() - e2))
3486 BOOST_MP_THROW_EXCEPTION(std::runtime_error("Exponent is too large to be represented as a power of 2."));
3487 t += e2;
3488 result = r2;
3489 }
3490
3491 while (result.compare(cpp_dec_float<Digits10, ExponentType, Allocator>::one()) >= 0)
3492 {
3493 result /= cpp_dec_float<Digits10, ExponentType, Allocator>::two();
3494 ++t;
3495 }
3496 while (result.compare(cpp_dec_float<Digits10, ExponentType, Allocator>::half()) < 0)
3497 {
3498 result *= cpp_dec_float<Digits10, ExponentType, Allocator>::two();
3499 --t;
3500 }
3501 *e = t;
3502 if (x.isneg())
3503 result.negate();
3504 }
3505
3506 template <unsigned Digits10, class ExponentType, class Allocator>
3507 inline typename std::enable_if< !std::is_same<ExponentType, int>::value>::type eval_frexp(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x, int* e)
3508 {
3509 typename cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type t;
3510 eval_frexp(result, x, &t);
3511 if ((t > (std::numeric_limits<int>::max)()) || (t < (std::numeric_limits<int>::min)()))
3512 BOOST_MP_THROW_EXCEPTION(std::runtime_error("Exponent is outside the range of an int"));
3513 *e = static_cast<int>(t);
3514 }
3515
3516 template <unsigned Digits10, class ExponentType, class Allocator>
3517 inline bool eval_is_zero(const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3518 {
3519 return val.iszero();
3520 }
3521 template <unsigned Digits10, class ExponentType, class Allocator>
3522 inline int eval_get_sign(const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3523 {
3524 return val.iszero() ? 0 : val.isneg() ? -1 : 1;
3525 }
3526
3527 template <unsigned Digits10, class ExponentType, class Allocator>
3528 inline std::size_t hash_value(const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
3529 {
3530 return val.hash();
3531 }
3532
3533 }
3534
3535 namespace detail {
3536
3537 template <unsigned Digits10, class ExponentType, class Allocator>
3538 struct transcendental_reduction_type<boost::multiprecision::backends::cpp_dec_float<Digits10, ExponentType, Allocator> >
3539 {
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549 using type = boost::multiprecision::backends::cpp_dec_float<Digits10 * 3, ExponentType, Allocator>;
3550 };
3551
3552 }
3553
3554
3555 }}
3556
3557 namespace std {
3558 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3559 class numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >
3560 {
3561 public:
3562 static constexpr bool is_specialized = true;
3563 static constexpr bool is_signed = true;
3564 static constexpr bool is_integer = false;
3565 static constexpr bool is_exact = false;
3566 static constexpr bool is_bounded = true;
3567 static constexpr bool is_modulo = false;
3568 static constexpr bool is_iec559 = false;
3569 static constexpr int digits = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10;
3570 static constexpr int digits10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10;
3571 static constexpr int max_digits10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_digits10;
3572 static constexpr typename boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type min_exponent = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp;
3573 static constexpr typename boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type min_exponent10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp10;
3574 static constexpr typename boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type max_exponent = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp;
3575 static constexpr typename boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type max_exponent10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp10;
3576 static constexpr int radix = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_radix;
3577 static constexpr std::float_round_style round_style = std::round_indeterminate;
3578 static constexpr bool has_infinity = true;
3579 static constexpr bool has_quiet_NaN = true;
3580 static constexpr bool has_signaling_NaN = false;
3581 static constexpr std::float_denorm_style has_denorm = std::denorm_absent;
3582 static constexpr bool has_denorm_loss = false;
3583 static constexpr bool traps = false;
3584 static constexpr bool tinyness_before = false;
3585
3586 static constexpr boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates>(min)() { return (boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::min)(); }
3587 static constexpr boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates>(max)() { return (boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::max)(); }
3588 static constexpr boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> lowest() { return boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::zero(); }
3589 static constexpr boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> epsilon() { return boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::eps(); }
3590 static constexpr boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> round_error() { return 0.5L; }
3591 static constexpr boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> infinity() { return boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::inf(); }
3592 static constexpr boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> quiet_NaN() { return boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::nan(); }
3593 static constexpr boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> signaling_NaN() { return boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::zero(); }
3594 static constexpr boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> denorm_min() { return (boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::min)(); }
3595 };
3596
3597 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3598 constexpr int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::digits;
3599 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3600 constexpr int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::digits10;
3601 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3602 constexpr int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::max_digits10;
3603 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3604 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_signed;
3605 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3606 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_integer;
3607 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3608 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_exact;
3609 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3610 constexpr int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::radix;
3611 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3612 constexpr typename boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::min_exponent;
3613 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3614 constexpr typename boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::min_exponent10;
3615 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3616 constexpr typename boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::max_exponent;
3617 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3618 constexpr typename boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::exponent_type numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::max_exponent10;
3619 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3620 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_infinity;
3621 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3622 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_quiet_NaN;
3623 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3624 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_signaling_NaN;
3625 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3626 constexpr float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_denorm;
3627 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3628 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_denorm_loss;
3629 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3630 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_iec559;
3631 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3632 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_bounded;
3633 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3634 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_modulo;
3635 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3636 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::traps;
3637 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3638 constexpr bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::tinyness_before;
3639 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3640 constexpr float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::round_style;
3641
3642 }
3643
3644 #ifdef BOOST_MP_MATH_AVAILABLE
3645 namespace boost {
3646 namespace math {
3647
3648 namespace policies {
3649
3650 template <unsigned Digits10, class ExponentType, class Allocator, class Policy, boost::multiprecision::expression_template_option ExpressionTemplates>
3651 struct precision<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates>, Policy>
3652 {
3653
3654
3655 static constexpr std::int32_t cpp_dec_float_digits10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10;
3656
3657 using precision_type = typename Policy::precision_type ;
3658 using digits_2 = digits2<static_cast<int>(((cpp_dec_float_digits10 + 1LL) * 1000LL) / 301LL)>;
3659 using type = typename std::conditional<
3660 ((digits_2::value <= precision_type::value) || (Policy::precision_type::value <= 0)),
3661
3662 digits_2,
3663
3664 precision_type>::type;
3665 };
3666
3667 }
3668
3669 }}
3670 #endif
3671
3672 #ifdef BOOST_MSVC
3673 #pragma warning(pop)
3674 #endif
3675
3676 #endif