]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/multiprecision/include/boost/multiprecision/cpp_dec_float.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / multiprecision / include / boost / multiprecision / cpp_dec_float.hpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////////////////////
2// Copyright Christopher Kormanyos 2002 - 2013.
3// Copyright 2011 -2013 John Maddock. Distributed under the Boost
4// Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// This work is based on an earlier work:
8// "Algorithm 910: A Portable C++ Multiple-Precision System for Special-Function Calculations",
9// in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. http://doi.acm.org/10.1145/1916461.1916469
10//
11// Note that there are no "noexcept" specifications on the functions in this file: there are too many
12// calls to lexical_cast (and similar) to easily analyse the code for correctness. So until compilers
13// can detect noexcept misuse at compile time, the only realistic option is to simply not use it here.
14//
15
16#ifndef BOOST_MP_CPP_DEC_FLOAT_BACKEND_HPP
17#define BOOST_MP_CPP_DEC_FLOAT_BACKEND_HPP
18
19#include <boost/config.hpp>
20#include <boost/cstdint.hpp>
21#include <limits>
22#ifndef BOOST_NO_CXX11_HDR_ARRAY
23#include <array>
24#else
25#include <boost/array.hpp>
26#endif
27#include <boost/cstdint.hpp>
28#include <boost/functional/hash_fwd.hpp>
29#include <boost/multiprecision/number.hpp>
30#include <boost/multiprecision/detail/big_lanczos.hpp>
31#include <boost/multiprecision/detail/dynamic_array.hpp>
32
33//
34// Headers required for Boost.Math integration:
35//
36#include <boost/math/policies/policy.hpp>
37//
38// Some includes we need from Boost.Math, since we rely on that library to provide these functions:
39//
40#include <boost/math/special_functions/asinh.hpp>
41#include <boost/math/special_functions/acosh.hpp>
42#include <boost/math/special_functions/atanh.hpp>
43#include <boost/math/special_functions/cbrt.hpp>
44#include <boost/math/special_functions/expm1.hpp>
45#include <boost/math/special_functions/gamma.hpp>
46
47#ifdef BOOST_MSVC
48#pragma warning(push)
49#pragma warning(disable:6326) // comparison of two constants
50#endif
51
52namespace boost{
53namespace multiprecision{
54namespace backends{
55
56template <unsigned Digits10, class ExponentType = boost::int32_t, class Allocator = void>
57class cpp_dec_float;
58
59} // namespace
60
61template <unsigned Digits10, class ExponentType, class Allocator>
62struct number_category<backends::cpp_dec_float<Digits10, ExponentType, Allocator> > : public mpl::int_<number_kind_floating_point>{};
63
64namespace backends{
65
66template <unsigned Digits10, class ExponentType, class Allocator>
67class cpp_dec_float
68{
69private:
70 static const boost::int32_t cpp_dec_float_digits10_setting = Digits10;
71
72 // We need at least 16-bits in the exponent type to do anything sensible:
73 BOOST_STATIC_ASSERT_MSG(boost::is_signed<ExponentType>::value, "ExponentType must be a signed built in integer type.");
74 BOOST_STATIC_ASSERT_MSG(sizeof(ExponentType) > 1, "ExponentType is too small.");
75
76public:
77 typedef mpl::list<boost::long_long_type> signed_types;
78 typedef mpl::list<boost::ulong_long_type> unsigned_types;
79 typedef mpl::list<long double> float_types;
80 typedef ExponentType exponent_type;
81
82 static const boost::int32_t cpp_dec_float_radix = 10L;
83 static const boost::int32_t cpp_dec_float_digits10_limit_lo = 9L;
84 static const boost::int32_t cpp_dec_float_digits10_limit_hi = boost::integer_traits<boost::int32_t>::const_max - 100;
85 static const boost::int32_t cpp_dec_float_digits10 = ((cpp_dec_float_digits10_setting < cpp_dec_float_digits10_limit_lo) ? cpp_dec_float_digits10_limit_lo : ((cpp_dec_float_digits10_setting > cpp_dec_float_digits10_limit_hi) ? cpp_dec_float_digits10_limit_hi : cpp_dec_float_digits10_setting));
86 static const ExponentType cpp_dec_float_max_exp10 = (static_cast<ExponentType>(1) << (std::numeric_limits<ExponentType>::digits - 5));
87 static const ExponentType cpp_dec_float_min_exp10 = -cpp_dec_float_max_exp10;
88 static const ExponentType cpp_dec_float_max_exp = cpp_dec_float_max_exp10;
89 static const ExponentType cpp_dec_float_min_exp = cpp_dec_float_min_exp10;
90
91 BOOST_STATIC_ASSERT((cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp10 == -cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp10));
92
93private:
94 static const boost::int32_t cpp_dec_float_elem_digits10 = 8L;
95 static const boost::int32_t cpp_dec_float_elem_mask = 100000000L;
96
97 BOOST_STATIC_ASSERT(0 == cpp_dec_float_max_exp10 % cpp_dec_float_elem_digits10);
98
99 // There are three guard limbs.
100 // 1) The first limb has 'play' from 1...8 decimal digits.
101 // 2) The last limb also has 'play' from 1...8 decimal digits.
102 // 3) One limb can get lost when justifying after multiply,
103 // as only half of the triangle is multiplied and a carry
104 // from below is missing.
105 static const boost::int32_t cpp_dec_float_elem_number_request = static_cast<boost::int32_t>((cpp_dec_float_digits10 / cpp_dec_float_elem_digits10) + (((cpp_dec_float_digits10 % cpp_dec_float_elem_digits10) != 0) ? 1 : 0));
106
107 // The number of elements needed (with a minimum of two) plus three added guard limbs.
108 static const boost::int32_t cpp_dec_float_elem_number = static_cast<boost::int32_t>(((cpp_dec_float_elem_number_request < 2L) ? 2L : cpp_dec_float_elem_number_request) + 3L);
109
110public:
111 static const boost::int32_t cpp_dec_float_total_digits10 = static_cast<boost::int32_t>(cpp_dec_float_elem_number * cpp_dec_float_elem_digits10);
112
113private:
114
115 typedef enum enum_fpclass_type
116 {
117 cpp_dec_float_finite,
118 cpp_dec_float_inf,
119 cpp_dec_float_NaN
120 }
121 fpclass_type;
122
123#ifndef BOOST_NO_CXX11_HDR_ARRAY
124 typedef typename mpl::if_<is_void<Allocator>,
125 std::array<boost::uint32_t, cpp_dec_float_elem_number>,
126 detail::dynamic_array<boost::uint32_t, cpp_dec_float_elem_number, Allocator>
127 >::type array_type;
128#else
129 typedef typename mpl::if_<is_void<Allocator>,
130 boost::array<boost::uint32_t, cpp_dec_float_elem_number>,
131 detail::dynamic_array<boost::uint32_t, cpp_dec_float_elem_number, Allocator>
132 >::type array_type;
133#endif
134
135 array_type data;
136 ExponentType exp;
137 bool neg;
138 fpclass_type fpclass;
139 boost::int32_t prec_elem;
140
141 //
142 // Special values constructor:
143 //
144 cpp_dec_float(fpclass_type c) :
145 data(),
146 exp (static_cast<ExponentType>(0)),
147 neg (false),
148 fpclass (c),
149 prec_elem(cpp_dec_float_elem_number) { }
150
151 //
152 // Static data initializer:
153 //
154 struct initializer
155 {
156 initializer()
157 {
158 cpp_dec_float<Digits10, ExponentType, Allocator>::nan();
159 cpp_dec_float<Digits10, ExponentType, Allocator>::inf();
160 (cpp_dec_float<Digits10, ExponentType, Allocator>::min)();
161 (cpp_dec_float<Digits10, ExponentType, Allocator>::max)();
162 cpp_dec_float<Digits10, ExponentType, Allocator>::zero();
163 cpp_dec_float<Digits10, ExponentType, Allocator>::one();
164 cpp_dec_float<Digits10, ExponentType, Allocator>::two();
165 cpp_dec_float<Digits10, ExponentType, Allocator>::half();
166 cpp_dec_float<Digits10, ExponentType, Allocator>::double_min();
167 cpp_dec_float<Digits10, ExponentType, Allocator>::double_max();
168 cpp_dec_float<Digits10, ExponentType, Allocator>::long_double_max();
169 cpp_dec_float<Digits10, ExponentType, Allocator>::long_double_min();
170 cpp_dec_float<Digits10, ExponentType, Allocator>::long_long_max();
171 cpp_dec_float<Digits10, ExponentType, Allocator>::long_long_min();
172 cpp_dec_float<Digits10, ExponentType, Allocator>::ulong_long_max();
173 cpp_dec_float<Digits10, ExponentType, Allocator>::eps();
174 cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(0);
175 }
176 void do_nothing(){}
177 };
178
179 static initializer init;
180
181public:
182 // Constructors
183 cpp_dec_float() BOOST_MP_NOEXCEPT_IF(noexcept(array_type())) :
184 data(),
185 exp (static_cast<ExponentType>(0)),
186 neg (false),
187 fpclass (cpp_dec_float_finite),
188 prec_elem(cpp_dec_float_elem_number) { }
189
190 cpp_dec_float(const char* s) :
191 data(),
192 exp (static_cast<ExponentType>(0)),
193 neg (false),
194 fpclass (cpp_dec_float_finite),
195 prec_elem(cpp_dec_float_elem_number)
196 {
197 *this = s;
198 }
199
200 template<class I>
201 cpp_dec_float(I i, typename enable_if<is_unsigned<I> >::type* = 0) :
202 data(),
203 exp (static_cast<ExponentType>(0)),
204 neg (false),
205 fpclass (cpp_dec_float_finite),
206 prec_elem(cpp_dec_float_elem_number)
207 {
208 from_unsigned_long_long(i);
209 }
210
211 template <class I>
212 cpp_dec_float(I i, typename enable_if<is_signed<I> >::type* = 0) :
213 data(),
214 exp (static_cast<ExponentType>(0)),
215 neg (false),
216 fpclass (cpp_dec_float_finite),
217 prec_elem(cpp_dec_float_elem_number)
218 {
219 if(i < 0)
220 {
221 from_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(i));
222 negate();
223 }
224 else
225 from_unsigned_long_long(i);
226 }
227
228 cpp_dec_float(const cpp_dec_float& f) BOOST_MP_NOEXCEPT_IF(noexcept(array_type(std::declval<const array_type&>()))) :
229 data (f.data),
230 exp (f.exp),
231 neg (f.neg),
232 fpclass (f.fpclass),
233 prec_elem(f.prec_elem) { }
234
235 template <unsigned D, class ET, class A>
236 cpp_dec_float(const cpp_dec_float<D, ET, A>& f, typename enable_if_c<D <= Digits10>::type* = 0) :
237 data(),
238 exp (f.exp),
239 neg (f.neg),
240 fpclass (static_cast<fpclass_type>(static_cast<int>(f.fpclass))),
241 prec_elem(cpp_dec_float_elem_number)
242 {
243 std::copy(f.data.begin(), f.data.begin() + f.prec_elem, data.begin());
244 }
245 template <unsigned D, class ET, class A>
246 explicit cpp_dec_float(const cpp_dec_float<D, ET, A>& f, typename disable_if_c<D <= Digits10>::type* = 0) :
247 data(),
248 exp (f.exp),
249 neg (f.neg),
250 fpclass (static_cast<fpclass_type>(static_cast<int>(f.fpclass))),
251 prec_elem(cpp_dec_float_elem_number)
252 {
253 // TODO: this doesn't round!
254 std::copy(f.data.begin(), f.data.begin() + prec_elem, data.begin());
255 }
256
257 template <class F>
258 cpp_dec_float(const F val, typename enable_if<is_floating_point<F> >::type* = 0) :
259 data(),
260 exp (static_cast<ExponentType>(0)),
261 neg (false),
262 fpclass (cpp_dec_float_finite),
263 prec_elem(cpp_dec_float_elem_number)
264 {
265 *this = val;
266 }
267
268 cpp_dec_float(const double mantissa, const ExponentType exponent);
269
270 std::size_t hash()const
271 {
272 std::size_t result = 0;
273 for(int i = 0; i < prec_elem; ++i)
274 boost::hash_combine(result, data[i]);
275 boost::hash_combine(result, exp);
276 boost::hash_combine(result, neg);
277 boost::hash_combine(result, fpclass);
278 return result;
279 }
280
281 // Specific special values.
282 static const cpp_dec_float& nan()
283 {
284 static const cpp_dec_float val(cpp_dec_float_NaN);
285 init.do_nothing();
286 return val;
287 }
288
289 static const cpp_dec_float& inf()
290 {
291 static const cpp_dec_float val(cpp_dec_float_inf);
292 init.do_nothing();
293 return val;
294 }
295
296 static const cpp_dec_float& (max)()
297 {
298 init.do_nothing();
299 static cpp_dec_float val_max = std::string("1.0e" + boost::lexical_cast<std::string>(cpp_dec_float_max_exp10)).c_str();
300 return val_max;
301 }
302
303 static const cpp_dec_float& (min)()
304 {
305 init.do_nothing();
306 static cpp_dec_float val_min = std::string("1.0e" + boost::lexical_cast<std::string>(cpp_dec_float_min_exp10)).c_str();
307 return val_min;
308 }
309
310 static const cpp_dec_float& zero()
311 {
312 init.do_nothing();
313 static cpp_dec_float val(static_cast<boost::ulong_long_type>(0u));
314 return val;
315 }
316
317 static const cpp_dec_float& one()
318 {
319 init.do_nothing();
320 static cpp_dec_float val(static_cast<boost::ulong_long_type>(1u));
321 return val;
322 }
323
324 static const cpp_dec_float& two()
325 {
326 init.do_nothing();
327 static cpp_dec_float val(static_cast<boost::ulong_long_type>(2u));
328 return val;
329 }
330
331 static const cpp_dec_float& half()
332 {
333 init.do_nothing();
334 static cpp_dec_float val(0.5L);
335 return val;
336 }
337
338 static const cpp_dec_float& double_min()
339 {
340 init.do_nothing();
341 static cpp_dec_float val(static_cast<long double>((std::numeric_limits<double>::min)()));
342 return val;
343 }
344
345 static const cpp_dec_float& double_max()
346 {
347 init.do_nothing();
348 static cpp_dec_float val(static_cast<long double>((std::numeric_limits<double>::max)()));
349 return val;
350 }
351
352 static const cpp_dec_float& long_double_min()
353 {
354 init.do_nothing();
355#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
356 static cpp_dec_float val(static_cast<long double>((std::numeric_limits<double>::min)()));
357#else
358 static cpp_dec_float val((std::numeric_limits<long double>::min)());
359#endif
360 return val;
361 }
362
363 static const cpp_dec_float& long_double_max()
364 {
365 init.do_nothing();
366#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
367 static cpp_dec_float val(static_cast<long double>((std::numeric_limits<double>::max)()));
368#else
369 static cpp_dec_float val((std::numeric_limits<long double>::max)());
370#endif
371 return val;
372 }
373
374 static const cpp_dec_float& long_long_max()
375 {
376 init.do_nothing();
377 static cpp_dec_float val((std::numeric_limits<boost::long_long_type>::max)());
378 return val;
379 }
380
381 static const cpp_dec_float& long_long_min()
382 {
383 init.do_nothing();
384 static cpp_dec_float val((std::numeric_limits<boost::long_long_type>::min)());
385 return val;
386 }
387
388 static const cpp_dec_float& ulong_long_max()
389 {
390 init.do_nothing();
391 static cpp_dec_float val((std::numeric_limits<boost::ulong_long_type>::max)());
392 return val;
393 }
394
395 static const cpp_dec_float& eps()
396 {
397 init.do_nothing();
398 static cpp_dec_float val(1.0, 1 - static_cast<int>(cpp_dec_float_digits10));
399 return val;
400 }
401
402 // Basic operations.
403 cpp_dec_float& operator=(const cpp_dec_float& v) BOOST_MP_NOEXCEPT_IF(noexcept(std::declval<array_type&>() = std::declval<const array_type&>()))
404 {
405 data = v.data;
406 exp = v.exp;
407 neg = v.neg;
408 fpclass = v.fpclass;
409 prec_elem = v.prec_elem;
410 return *this;
411 }
412
413 template <unsigned D>
414 cpp_dec_float& operator=(const cpp_dec_float<D>& f)
415 {
416 exp = f.exp;
417 neg = f.neg;
418 fpclass = static_cast<enum_fpclass_type>(static_cast<int>(f.fpclass));
419 unsigned elems = (std::min)(f.prec_elem, cpp_dec_float_elem_number);
420 std::copy(f.data.begin(), f.data.begin() + elems, data.begin());
421 std::fill(data.begin() + elems, data.end(), 0);
422 prec_elem = cpp_dec_float_elem_number;
423 return *this;
424 }
425
426 cpp_dec_float& operator=(boost::long_long_type v)
427 {
428 if(v < 0)
429 {
430 from_unsigned_long_long(-v);
431 negate();
432 }
433 else
434 from_unsigned_long_long(v);
435 return *this;
436 }
437
438 cpp_dec_float& operator=(boost::ulong_long_type v)
439 {
440 from_unsigned_long_long(v);
441 return *this;
442 }
443
444 cpp_dec_float& operator=(long double v);
445
446 cpp_dec_float& operator=(const char* v)
447 {
448 rd_string(v);
449 return *this;
450 }
451
452 cpp_dec_float& operator+=(const cpp_dec_float& v);
453 cpp_dec_float& operator-=(const cpp_dec_float& v);
454 cpp_dec_float& operator*=(const cpp_dec_float& v);
455 cpp_dec_float& operator/=(const cpp_dec_float& v);
456
457 cpp_dec_float& add_unsigned_long_long(const boost::ulong_long_type n)
458 {
459 cpp_dec_float t;
460 t.from_unsigned_long_long(n);
461 return *this += t;
462 }
463
464 cpp_dec_float& sub_unsigned_long_long(const boost::ulong_long_type n)
465 {
466 cpp_dec_float t;
467 t.from_unsigned_long_long(n);
468 return *this -= t;
469 }
470
471 cpp_dec_float& mul_unsigned_long_long(const boost::ulong_long_type n);
472 cpp_dec_float& div_unsigned_long_long(const boost::ulong_long_type n);
473
474 // Elementary primitives.
475 cpp_dec_float& calculate_inv ();
476 cpp_dec_float& calculate_sqrt();
477
478 void negate()
479 {
480 if(!iszero())
481 neg = !neg;
482 }
483
484 // Comparison functions
485 bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION() const { return (fpclass == cpp_dec_float_NaN); }
486 bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION() const { return (fpclass == cpp_dec_float_inf); }
487 bool isfinite BOOST_PREVENT_MACRO_SUBSTITUTION() const { return (fpclass == cpp_dec_float_finite); }
488
489 bool iszero () const
490 {
491 return ((fpclass == cpp_dec_float_finite) && (data[0u] == 0u));
492 }
493
494 bool isone () const;
495 bool isint () const;
496 bool isneg () const { return neg; }
497
498 // Operators pre-increment and pre-decrement
499 cpp_dec_float& operator++()
500 {
501 return *this += one();
502 }
503
504 cpp_dec_float& operator--()
505 {
506 return *this -= one();
507 }
508
509 std::string str(boost::intmax_t digits, std::ios_base::fmtflags f)const;
510
511 int compare(const cpp_dec_float& v)const;
512
513 template <class V>
514 int compare(const V& v)const
515 {
516 cpp_dec_float<Digits10, ExponentType, Allocator> t;
517 t = v;
518 return compare(t);
519 }
520
521 void swap(cpp_dec_float& v)
522 {
523 data.swap(v.data);
524 std::swap(exp, v.exp);
525 std::swap(neg, v.neg);
526 std::swap(fpclass, v.fpclass);
527 std::swap(prec_elem, v.prec_elem);
528 }
529
530 double extract_double() const;
531 long double extract_long_double() const;
532 boost::long_long_type extract_signed_long_long() const;
533 boost::ulong_long_type extract_unsigned_long_long() const;
534 void extract_parts(double& mantissa, ExponentType& exponent) const;
535 cpp_dec_float extract_integer_part() const;
536
537 void precision(const boost::int32_t prec_digits)
538 {
539 if(prec_digits >= cpp_dec_float_total_digits10)
540 {
541 prec_elem = cpp_dec_float_elem_number;
542 }
543 else
544 {
545 const boost::int32_t elems = static_cast<boost::int32_t>( static_cast<boost::int32_t>( (prec_digits + (cpp_dec_float_elem_digits10 / 2)) / cpp_dec_float_elem_digits10)
546 + static_cast<boost::int32_t>(((prec_digits % cpp_dec_float_elem_digits10) != 0) ? 1 : 0));
547
548 prec_elem = (std::min)(cpp_dec_float_elem_number, (std::max)(elems, static_cast<boost::int32_t>(2)));
549 }
550 }
551 static cpp_dec_float pow2(boost::long_long_type i);
552 ExponentType order()const
553 {
554 const bool bo_order_is_zero = ((!(isfinite)()) || (data[0] == static_cast<boost::uint32_t>(0u)));
555 //
556 // Binary search to find the order of the leading term:
557 //
558 ExponentType prefix = 0;
559
560 if(data[0] >= 100000UL)
561 {
562 if(data[0] >= 10000000UL)
563 {
564 if(data[0] >= 100000000UL)
565 {
566 if(data[0] >= 1000000000UL)
567 prefix = 9;
568 else
569 prefix = 8;
570 }
571 else
572 prefix = 7;
573 }
574 else
575 {
576 if(data[0] >= 1000000UL)
577 prefix = 6;
578 else
579 prefix = 5;
580 }
581 }
582 else
583 {
584 if(data[0] >= 1000UL)
585 {
586 if(data[0] >= 10000UL)
587 prefix = 4;
588 else
589 prefix = 3;
590 }
591 else
592 {
593 if(data[0] >= 100)
594 prefix = 2;
595 else if(data[0] >= 10)
596 prefix = 1;
597 }
598 }
599
600 return (bo_order_is_zero ? static_cast<ExponentType>(0) : static_cast<ExponentType>(exp + prefix));
601 }
602
603 template<class Archive>
604 void serialize(Archive & ar, const unsigned int /*version*/)
605 {
606 for(unsigned i = 0; i < data.size(); ++i)
607 ar & data[i];
608 ar & exp;
609 ar & neg;
610 ar & fpclass;
611 ar & prec_elem;
612 }
613
614private:
615 static bool data_elem_is_non_zero_predicate(const boost::uint32_t& d) { return (d != static_cast<boost::uint32_t>(0u)); }
616 static bool data_elem_is_non_nine_predicate(const boost::uint32_t& d) { return (d != static_cast<boost::uint32_t>(cpp_dec_float::cpp_dec_float_elem_mask - 1)); }
617 static bool char_is_nonzero_predicate(const char& c) { return (c != static_cast<char>('0')); }
618
619 void from_unsigned_long_long(const boost::ulong_long_type u);
620
621 int cmp_data(const array_type& vd) const;
622
623
624 static boost::uint32_t mul_loop_uv(boost::uint32_t* const u, const boost::uint32_t* const v, const boost::int32_t p);
625 static boost::uint32_t mul_loop_n (boost::uint32_t* const u, boost::uint32_t n, const boost::int32_t p);
626 static boost::uint32_t div_loop_n (boost::uint32_t* const u, boost::uint32_t n, const boost::int32_t p);
627
628 bool rd_string(const char* const s);
629
630 template <unsigned D, class ET, class A>
631 friend class cpp_dec_float;
632};
633
634template <unsigned Digits10, class ExponentType, class Allocator>
635typename cpp_dec_float<Digits10, ExponentType, Allocator>::initializer cpp_dec_float<Digits10, ExponentType, Allocator>::init;
636
637template <unsigned Digits10, class ExponentType, class Allocator>
638const boost::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_radix;
639template <unsigned Digits10, class ExponentType, class Allocator>
640const boost::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10_setting;
641template <unsigned Digits10, class ExponentType, class Allocator>
642const boost::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10_limit_lo;
643template <unsigned Digits10, class ExponentType, class Allocator>
644const boost::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10_limit_hi;
645template <unsigned Digits10, class ExponentType, class Allocator>
646const boost::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10;
647template <unsigned Digits10, class ExponentType, class Allocator>
648const ExponentType cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp;
649template <unsigned Digits10, class ExponentType, class Allocator>
650const ExponentType cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp;
651template <unsigned Digits10, class ExponentType, class Allocator>
652const ExponentType cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp10;
653template <unsigned Digits10, class ExponentType, class Allocator>
654const ExponentType cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp10;
655template <unsigned Digits10, class ExponentType, class Allocator>
656const boost::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_elem_digits10;
657template <unsigned Digits10, class ExponentType, class Allocator>
658const boost::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_elem_number_request;
659template <unsigned Digits10, class ExponentType, class Allocator>
660const boost::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_elem_number;
661template <unsigned Digits10, class ExponentType, class Allocator>
662const boost::int32_t cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_elem_mask;
663
664template <unsigned Digits10, class ExponentType, class Allocator>
665cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::operator+=(const cpp_dec_float<Digits10, ExponentType, Allocator>& v)
666{
667 if((isnan)())
668 {
669 return *this;
670 }
671
672 if((isinf)())
673 {
674 if((v.isinf)() && (isneg() != v.isneg()))
675 {
676 *this = nan();
677 }
678 return *this;
679 }
680
681 if(iszero())
682 {
683 return operator=(v);
684 }
685
686 if((v.isnan)() || (v.isinf)())
687 {
688 *this = v;
689 return *this;
690 }
691
692 // Get the offset for the add/sub operation.
693 static const ExponentType max_delta_exp = static_cast<ExponentType>((cpp_dec_float_elem_number - 1) * cpp_dec_float_elem_digits10);
694
695 const ExponentType ofs_exp = static_cast<ExponentType>(exp - v.exp);
696
697 // Check if the operation is out of range, requiring special handling.
698 if(v.iszero() || (ofs_exp > max_delta_exp))
699 {
700 // Result is *this unchanged since v is negligible compared to *this.
701 return *this;
702 }
703 else if(ofs_exp < -max_delta_exp)
704 {
705 // Result is *this = v since *this is negligible compared to v.
706 return operator=(v);
707 }
708
709 // Do the add/sub operation.
710
711 typename array_type::iterator p_u = data.begin();
712 typename array_type::const_iterator p_v = v.data.begin();
713 bool b_copy = false;
714 const boost::int32_t ofs = static_cast<boost::int32_t>(static_cast<boost::int32_t>(ofs_exp) / cpp_dec_float_elem_digits10);
715 array_type n_data;
716
717 if(neg == v.neg)
718 {
719 // Add v to *this, where the data array of either *this or v
720 // might have to be treated with a positive, negative or zero offset.
721 // The result is stored in *this. The data are added one element
722 // at a time, each element with carry.
723 if(ofs >= static_cast<boost::int32_t>(0))
724 {
725 std::copy(v.data.begin(), v.data.end() - static_cast<size_t>(ofs), n_data.begin() + static_cast<size_t>(ofs));
726 std::fill(n_data.begin(), n_data.begin() + static_cast<size_t>(ofs), static_cast<boost::uint32_t>(0u));
727 p_v = n_data.begin();
728 }
729 else
730 {
731 std::copy(data.begin(), data.end() - static_cast<size_t>(-ofs), n_data.begin() + static_cast<size_t>(-ofs));
732 std::fill(n_data.begin(), n_data.begin() + static_cast<size_t>(-ofs), static_cast<boost::uint32_t>(0u));
733 p_u = n_data.begin();
734 b_copy = true;
735 }
736
737 // Addition algorithm
738 boost::uint32_t carry = static_cast<boost::uint32_t>(0u);
739
740 for(boost::int32_t j = static_cast<boost::int32_t>(cpp_dec_float_elem_number - static_cast<boost::int32_t>(1)); j >= static_cast<boost::int32_t>(0); j--)
741 {
742 boost::uint32_t t = static_cast<boost::uint32_t>(static_cast<boost::uint32_t>(p_u[j] + p_v[j]) + carry);
743 carry = t / static_cast<boost::uint32_t>(cpp_dec_float_elem_mask);
744 p_u[j] = static_cast<boost::uint32_t>(t - static_cast<boost::uint32_t>(carry * static_cast<boost::uint32_t>(cpp_dec_float_elem_mask)));
745 }
746
747 if(b_copy)
748 {
749 data = n_data;
750 exp = v.exp;
751 }
752
753 // There needs to be a carry into the element -1 of the array data
754 if(carry != static_cast<boost::uint32_t>(0u))
755 {
756 std::copy_backward(data.begin(), data.end() - static_cast<std::size_t>(1u), data.end());
757 data[0] = carry;
758 exp += static_cast<ExponentType>(cpp_dec_float_elem_digits10);
759 }
760 }
761 else
762 {
763 // Subtract v from *this, where the data array of either *this or v
764 // might have to be treated with a positive, negative or zero offset.
765 if((ofs > static_cast<boost::int32_t>(0))
766 || ( (ofs == static_cast<boost::int32_t>(0))
767 && (cmp_data(v.data) > static_cast<boost::int32_t>(0)))
768 )
769 {
770 // In this case, |u| > |v| and ofs is positive.
771 // Copy the data of v, shifted down to a lower value
772 // into the data array m_n. Set the operand pointer p_v
773 // to point to the copied, shifted data m_n.
774 std::copy(v.data.begin(), v.data.end() - static_cast<size_t>(ofs), n_data.begin() + static_cast<size_t>(ofs));
775 std::fill(n_data.begin(), n_data.begin() + static_cast<size_t>(ofs), static_cast<boost::uint32_t>(0u));
776 p_v = n_data.begin();
777 }
778 else
779 {
780 if(ofs != static_cast<boost::int32_t>(0))
781 {
782 // In this case, |u| < |v| and ofs is negative.
783 // Shift the data of u down to a lower value.
784 std::copy_backward(data.begin(), data.end() - static_cast<size_t>(-ofs), data.end());
785 std::fill(data.begin(), data.begin() + static_cast<size_t>(-ofs), static_cast<boost::uint32_t>(0u));
786 }
787
788 // Copy the data of v into the data array n_data.
789 // Set the u-pointer p_u to point to m_n and the
790 // operand pointer p_v to point to the shifted
791 // data m_data.
792 n_data = v.data;
793 p_u = n_data.begin();
794 p_v = data.begin();
795 b_copy = true;
796 }
797
798 boost::int32_t j;
799
800 // Subtraction algorithm
801 boost::int32_t borrow = static_cast<boost::int32_t>(0);
802
803 for(j = static_cast<boost::int32_t>(cpp_dec_float_elem_number - static_cast<boost::int32_t>(1)); j >= static_cast<boost::int32_t>(0); j--)
804 {
805 boost::int32_t t = static_cast<boost::int32_t>(static_cast<boost::int32_t>( static_cast<boost::int32_t>(p_u[j])
806 - static_cast<boost::int32_t>(p_v[j])) - borrow);
807
808 // Underflow? Borrow?
809 if(t < static_cast<boost::int32_t>(0))
810 {
811 // Yes, underflow and borrow
812 t += static_cast<boost::int32_t>(cpp_dec_float_elem_mask);
813 borrow = static_cast<boost::int32_t>(1);
814 }
815 else
816 {
817 borrow = static_cast<boost::int32_t>(0);
818 }
819
820 p_u[j] = static_cast<boost::uint32_t>(static_cast<boost::uint32_t>(t) % static_cast<boost::uint32_t>(cpp_dec_float_elem_mask));
821 }
822
823 if(b_copy)
824 {
825 data = n_data;
826 exp = v.exp;
827 neg = v.neg;
828 }
829
830 // Is it necessary to justify the data?
831 const typename array_type::const_iterator first_nonzero_elem = std::find_if(data.begin(), data.end(), data_elem_is_non_zero_predicate);
832
833 if(first_nonzero_elem != data.begin())
834 {
835 if(first_nonzero_elem == data.end())
836 {
837 // This result of the subtraction is exactly zero.
838 // Reset the sign and the exponent.
839 neg = false;
840 exp = static_cast<ExponentType>(0);
841 }
842 else
843 {
844 // Justify the data
845 const std::size_t sj = static_cast<std::size_t>(std::distance<typename array_type::const_iterator>(data.begin(), first_nonzero_elem));
846
847 std::copy(data.begin() + static_cast<std::size_t>(sj), data.end(), data.begin());
848 std::fill(data.end() - sj, data.end(), static_cast<boost::uint32_t>(0u));
849
850 exp -= static_cast<ExponentType>(sj * static_cast<std::size_t>(cpp_dec_float_elem_digits10));
851 }
852 }
853 }
854
855 // Handle underflow.
856 if(iszero())
857 return (*this = zero());
858
859 // Check for potential overflow.
860 const bool b_result_might_overflow = (exp >= static_cast<ExponentType>(cpp_dec_float_max_exp10));
861
862 // Handle overflow.
863 if(b_result_might_overflow)
864 {
865 const bool b_result_is_neg = neg;
866 neg = false;
867
868 if(compare((cpp_dec_float::max)()) > 0)
869 *this = inf();
870
871 neg = b_result_is_neg;
872 }
873
874 return *this;
875}
876
877template <unsigned Digits10, class ExponentType, class Allocator>
878cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::operator-=(const cpp_dec_float<Digits10, ExponentType, Allocator>& v)
879{
880 // Use *this - v = -(-*this + v).
881 negate();
882 *this += v;
883 negate();
884 return *this;
885}
886
887template <unsigned Digits10, class ExponentType, class Allocator>
888cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::operator*=(const cpp_dec_float<Digits10, ExponentType, Allocator>& v)
889{
890 // Evaluate the sign of the result.
891 const bool b_result_is_neg = (neg != v.neg);
892
893 // Artificially set the sign of the result to be positive.
894 neg = false;
895
896 // Handle special cases like zero, inf and NaN.
897 const bool b_u_is_inf = (isinf)();
898 const bool b_v_is_inf = (v.isinf)();
899 const bool b_u_is_zero = iszero();
900 const bool b_v_is_zero = v.iszero();
901
902 if( ((isnan)() || (v.isnan)())
903 || (b_u_is_inf && b_v_is_zero)
904 || (b_v_is_inf && b_u_is_zero)
905 )
906 {
907 *this = nan();
908 return *this;
909 }
910
911 if(b_u_is_inf || b_v_is_inf)
912 {
913 *this = inf();
914 if(b_result_is_neg)
915 negate();
916 return *this;
917 }
918
919 if(b_u_is_zero || b_v_is_zero)
920 {
921 return *this = zero();
922 }
923
924 // Check for potential overflow or underflow.
925 const bool b_result_might_overflow = ((exp + v.exp) >= static_cast<ExponentType>(cpp_dec_float_max_exp10));
926 const bool b_result_might_underflow = ((exp + v.exp) <= static_cast<ExponentType>(cpp_dec_float_min_exp10));
927
928 // Set the exponent of the result.
929 exp += v.exp;
930
931 const boost::int32_t prec_mul = (std::min)(prec_elem, v.prec_elem);
932
933 const boost::uint32_t carry = mul_loop_uv(data.data(), v.data.data(), prec_mul);
934
935 // Handle a potential carry.
936 if(carry != static_cast<boost::uint32_t>(0u))
937 {
938 exp += cpp_dec_float_elem_digits10;
939
940 // Shift the result of the multiplication one element to the right...
941 std::copy_backward(data.begin(),
942 data.begin() + static_cast<std::size_t>(prec_elem - static_cast<boost::int32_t>(1)),
943 data.begin() + static_cast<std::size_t>(prec_elem));
944
945 // ... And insert the carry.
946 data.front() = carry;
947 }
948
949 // Handle overflow.
950 if(b_result_might_overflow && (compare((cpp_dec_float::max)()) > 0))
951 {
952 *this = inf();
953 }
954
955 // Handle underflow.
956 if(b_result_might_underflow && (compare((cpp_dec_float::min)()) < 0))
957 {
958 *this = zero();
959
960 return *this;
961 }
962
963 // Set the sign of the result.
964 neg = b_result_is_neg;
965
966 return *this;
967}
968
969template <unsigned Digits10, class ExponentType, class Allocator>
970cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::operator/=(const cpp_dec_float<Digits10, ExponentType, Allocator>& v)
971{
972 if(iszero())
973 {
974 if((v.isnan)())
975 {
976 return *this = v;
977 }
978 else if(v.iszero())
979 {
980 return *this = nan();
981 }
982 }
983
984 const bool u_and_v_are_finite_and_identical = ( (isfinite)()
985 && (fpclass == v.fpclass)
986 && (exp == v.exp)
987 && (cmp_data(v.data) == static_cast<boost::int32_t>(0)));
988
989 if(u_and_v_are_finite_and_identical)
990 {
991 if(neg != v.neg)
992 {
993 *this = one();
994 negate();
995 }
996 else
997 *this = one();
998 return *this;
999 }
1000 else
1001 {
1002 cpp_dec_float t(v);
1003 t.calculate_inv();
1004 return operator*=(t);
1005 }
1006}
1007
1008template <unsigned Digits10, class ExponentType, class Allocator>
1009cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::mul_unsigned_long_long(const boost::ulong_long_type n)
1010{
1011 // Multiply *this with a constant boost::ulong_long_type.
1012
1013 // Evaluate the sign of the result.
1014 const bool b_neg = neg;
1015
1016 // Artificially set the sign of the result to be positive.
1017 neg = false;
1018
1019 // Handle special cases like zero, inf and NaN.
1020 const bool b_u_is_inf = (isinf)();
1021 const bool b_n_is_zero = (n == static_cast<boost::int32_t>(0));
1022
1023 if((isnan)() || (b_u_is_inf && b_n_is_zero))
1024 {
1025 return (*this = nan());
1026 }
1027
1028 if(b_u_is_inf)
1029 {
1030 *this = inf();
1031 if(b_neg)
1032 negate();
1033 return *this;
1034 }
1035
1036 if(iszero() || b_n_is_zero)
1037 {
1038 // Multiplication by zero.
1039 return *this = zero();
1040 }
1041
1042 if(n >= static_cast<boost::ulong_long_type>(cpp_dec_float_elem_mask))
1043 {
1044 neg = b_neg;
1045 cpp_dec_float t;
1046 t = n;
1047 return operator*=(t);
1048 }
1049
1050 if(n == static_cast<boost::ulong_long_type>(1u))
1051 {
1052 neg = b_neg;
1053 return *this;
1054 }
1055
1056 // Set up the multiplication loop.
1057 const boost::uint32_t nn = static_cast<boost::uint32_t>(n);
1058 const boost::uint32_t carry = mul_loop_n(data.data(), nn, prec_elem);
1059
1060 // Handle the carry and adjust the exponent.
1061 if(carry != static_cast<boost::uint32_t>(0u))
1062 {
1063 exp += static_cast<ExponentType>(cpp_dec_float_elem_digits10);
1064
1065 // Shift the result of the multiplication one element to the right.
1066 std::copy_backward(data.begin(),
1067 data.begin() + static_cast<std::size_t>(prec_elem - static_cast<boost::int32_t>(1)),
1068 data.begin() + static_cast<std::size_t>(prec_elem));
1069
1070 data.front() = static_cast<boost::uint32_t>(carry);
1071 }
1072
1073 // Check for potential overflow.
1074 const bool b_result_might_overflow = (exp >= cpp_dec_float_max_exp10);
1075
1076 // Handle overflow.
1077 if(b_result_might_overflow && (compare((cpp_dec_float::max)()) > 0))
1078 {
1079 *this = inf();
1080 }
1081
1082 // Set the sign.
1083 neg = b_neg;
1084
1085 return *this;
1086}
1087
1088template <unsigned Digits10, class ExponentType, class Allocator>
1089cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::div_unsigned_long_long(const boost::ulong_long_type n)
1090{
1091 // Divide *this by a constant boost::ulong_long_type.
1092
1093 // Evaluate the sign of the result.
1094 const bool b_neg = neg;
1095
1096 // Artificially set the sign of the result to be positive.
1097 neg = false;
1098
1099 // Handle special cases like zero, inf and NaN.
1100 if((isnan)())
1101 {
1102 return *this;
1103 }
1104
1105 if((isinf)())
1106 {
1107 *this = inf();
1108 if(b_neg)
1109 negate();
1110 return *this;
1111 }
1112
1113 if(n == static_cast<boost::ulong_long_type>(0u))
1114 {
1115 // Divide by 0.
1116 if(iszero())
1117 {
1118 *this = nan();
1119 return *this;
1120 }
1121 else
1122 {
1123 *this = inf();
1124 if(isneg())
1125 negate();
1126 return *this;
1127 }
1128 }
1129
1130 if(iszero())
1131 {
1132 return *this;
1133 }
1134
1135 if(n >= static_cast<boost::ulong_long_type>(cpp_dec_float_elem_mask))
1136 {
1137 neg = b_neg;
1138 cpp_dec_float t;
1139 t = n;
1140 return operator/=(t);
1141 }
1142
1143 const boost::uint32_t nn = static_cast<boost::uint32_t>(n);
1144
1145 if(nn > static_cast<boost::uint32_t>(1u))
1146 {
1147 // Do the division loop.
1148 const boost::uint32_t prev = div_loop_n(data.data(), nn, prec_elem);
1149
1150 // Determine if one leading zero is in the result data.
1151 if(data[0] == static_cast<boost::uint32_t>(0u))
1152 {
1153 // Adjust the exponent
1154 exp -= static_cast<ExponentType>(cpp_dec_float_elem_digits10);
1155
1156 // Shift result of the division one element to the left.
1157 std::copy(data.begin() + static_cast<std::size_t>(1u),
1158 data.begin() + static_cast<std::size_t>(prec_elem - static_cast<boost::int32_t>(1)),
1159 data.begin());
1160
1161 data[prec_elem - static_cast<boost::int32_t>(1)] = static_cast<boost::uint32_t>(static_cast<boost::uint64_t>(prev * static_cast<boost::uint64_t>(cpp_dec_float_elem_mask)) / nn);
1162 }
1163 }
1164
1165 // Check for potential underflow.
1166 const bool b_result_might_underflow = (exp <= cpp_dec_float_min_exp10);
1167
1168 // Handle underflow.
1169 if(b_result_might_underflow && (compare((cpp_dec_float::min)()) < 0))
1170 return (*this = zero());
1171
1172 // Set the sign of the result.
1173 neg = b_neg;
1174
1175 return *this;
1176}
1177
1178template <unsigned Digits10, class ExponentType, class Allocator>
1179cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::calculate_inv()
1180{
1181 // Compute the inverse of *this.
1182 const bool b_neg = neg;
1183
1184 neg = false;
1185
1186 // Handle special cases like zero, inf and NaN.
1187 if(iszero())
1188 {
1189 *this = inf();
1190 if(b_neg)
1191 negate();
1192 return *this;
1193 }
1194
1195 if((isnan)())
1196 {
1197 return *this;
1198 }
1199
1200 if((isinf)())
1201 {
1202 return *this = zero();
1203 }
1204
1205 if(isone())
1206 {
1207 if(b_neg)
1208 negate();
1209 return *this;
1210 }
1211
1212 // Save the original *this.
1213 cpp_dec_float<Digits10, ExponentType, Allocator> x(*this);
1214
1215 // Generate the initial estimate using division.
1216 // Extract the mantissa and exponent for a "manual"
1217 // computation of the estimate.
1218 double dd;
1219 ExponentType ne;
1220 x.extract_parts(dd, ne);
1221
1222 // Do the inverse estimate using double precision estimates of mantissa and exponent.
1223 operator=(cpp_dec_float<Digits10, ExponentType, Allocator>(1.0 / dd, -ne));
1224
1225 // Compute the inverse of *this. Quadratically convergent Newton-Raphson iteration
1226 // is used. During the iterative steps, the precision of the calculation is limited
1227 // to the minimum required in order to minimize the run-time.
1228
1229 static const boost::int32_t double_digits10_minus_a_few = std::numeric_limits<double>::digits10 - 3;
1230
1231 for(boost::int32_t digits = double_digits10_minus_a_few; digits <= cpp_dec_float_total_digits10; digits *= static_cast<boost::int32_t>(2))
1232 {
1233 // Adjust precision of the terms.
1234 precision(static_cast<boost::int32_t>((digits + 10) * static_cast<boost::int32_t>(2)));
1235 x.precision(static_cast<boost::int32_t>((digits + 10) * static_cast<boost::int32_t>(2)));
1236
1237 // Next iteration.
1238 cpp_dec_float t(*this);
1239 t *= x;
1240 t -= two();
1241 t.negate();
1242 *this *= t;
1243 }
1244
1245 neg = b_neg;
1246
1247 prec_elem = cpp_dec_float_elem_number;
1248
1249 return *this;
1250}
1251
1252template <unsigned Digits10, class ExponentType, class Allocator>
1253cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::calculate_sqrt()
1254{
1255 // Compute the square root of *this.
1256
1257 if(isneg() || (!(isfinite)()))
1258 {
1259 *this = nan();
1260 return *this;
1261 }
1262
1263 if(iszero() || isone())
1264 {
1265 return *this;
1266 }
1267
1268 // Save the original *this.
1269 cpp_dec_float<Digits10, ExponentType, Allocator> x(*this);
1270
1271 // Generate the initial estimate using division.
1272 // Extract the mantissa and exponent for a "manual"
1273 // computation of the estimate.
1274 double dd;
1275 ExponentType ne;
1276 extract_parts(dd, ne);
1277
1278 // Force the exponent to be an even multiple of two.
1279 if((ne % static_cast<ExponentType>(2)) != static_cast<ExponentType>(0))
1280 {
1281 ++ne;
1282 dd /= 10.0;
1283 }
1284
1285 // Setup the iteration.
1286 // Estimate the square root using simple manipulations.
1287 const double sqd = std::sqrt(dd);
1288
1289 *this = cpp_dec_float<Digits10, ExponentType, Allocator>(sqd, static_cast<ExponentType>(ne / static_cast<ExponentType>(2)));
1290
1291 // Estimate 1.0 / (2.0 * x0) using simple manipulations.
1292 cpp_dec_float<Digits10, ExponentType, Allocator> vi(0.5 / sqd, static_cast<ExponentType>(-ne / static_cast<ExponentType>(2)));
1293
1294 // Compute the square root of x. Coupled Newton iteration
1295 // as described in "Pi Unleashed" is used. During the
1296 // iterative steps, the precision of the calculation is
1297 // limited to the minimum required in order to minimize
1298 // the run-time.
1299 //
1300 // Book references:
1301 // http://www.jjj.de/pibook/pibook.html
1302 // http://www.amazon.com/exec/obidos/tg/detail/-/3540665722/qid=1035535482/sr=8-7/ref=sr_8_7/104-3357872-6059916?v=glance&n=507846
1303
1304 static const boost::uint32_t double_digits10_minus_a_few = std::numeric_limits<double>::digits10 - 3;
1305
1306 for(boost::int32_t digits = double_digits10_minus_a_few; digits <= cpp_dec_float_total_digits10; digits *= 2u)
1307 {
1308 // Adjust precision of the terms.
1309 precision((digits + 10) * 2);
1310 vi.precision((digits + 10) * 2);
1311
1312 // Next iteration of vi
1313 cpp_dec_float t(*this);
1314 t *= vi;
1315 t.negate();
1316 t.mul_unsigned_long_long(2u);
1317 t += one();
1318 t *= vi;
1319 vi += t;
1320
1321 // Next iteration of *this
1322 t = *this;
1323 t *= *this;
1324 t.negate();
1325 t += x;
1326 t *= vi;
1327 *this += t;
1328 }
1329
1330 prec_elem = cpp_dec_float_elem_number;
1331
1332 return *this;
1333}
1334
1335template <unsigned Digits10, class ExponentType, class Allocator>
1336int cpp_dec_float<Digits10, ExponentType, Allocator>::cmp_data(const array_type& vd) const
1337{
1338 // Compare the data of *this with those of v.
1339 // Return +1 for *this > v
1340 // 0 for *this = v
1341 // -1 for *this < v
1342
1343 const std::pair<typename array_type::const_iterator, typename array_type::const_iterator> mismatch_pair = std::mismatch(data.begin(), data.end(), vd.begin());
1344
1345 const bool is_equal = ((mismatch_pair.first == data.end()) && (mismatch_pair.second == vd.end()));
1346
1347 if(is_equal)
1348 {
1349 return 0;
1350 }
1351 else
1352 {
1353 return ((*mismatch_pair.first > *mismatch_pair.second) ? 1 : -1);
1354 }
1355}
1356
1357template <unsigned Digits10, class ExponentType, class Allocator>
1358int cpp_dec_float<Digits10, ExponentType, Allocator>::compare(const cpp_dec_float& v) const
1359{
1360 // Compare v with *this.
1361 // Return +1 for *this > v
1362 // 0 for *this = v
1363 // -1 for *this < v
1364
1365 // Handle all non-finite cases.
1366 if((!(isfinite)()) || (!(v.isfinite)()))
1367 {
1368 // NaN can never equal NaN. Return an implementation-dependent
1369 // signed result. Also note that comparison of NaN with NaN
1370 // using operators greater-than or less-than is undefined.
1371 if((isnan)() || (v.isnan)()) { return ((isnan)() ? 1 : -1); }
1372
1373 if((isinf)() && (v.isinf)())
1374 {
1375 // Both *this and v are infinite. They are equal if they have the same sign.
1376 // Otherwise, *this is less than v if and only if *this is negative.
1377 return ((neg == v.neg) ? 0 : (neg ? -1 : 1));
1378 }
1379
1380 if((isinf)())
1381 {
1382 // *this is infinite, but v is finite.
1383 // So negative infinite *this is less than any finite v.
1384 // Whereas positive infinite *this is greater than any finite v.
1385 return (isneg() ? -1 : 1);
1386 }
1387 else
1388 {
1389 // *this is finite, and v is infinite.
1390 // So any finite *this is greater than negative infinite v.
1391 // Whereas any finite *this is less than positive infinite v.
1392 return (v.neg ? 1 : -1);
1393 }
1394 }
1395
1396 // And now handle all *finite* cases.
1397 if(iszero())
1398 {
1399 // The value of *this is zero and v is either zero or non-zero.
1400 return (v.iszero() ? 0
1401 : (v.neg ? 1 : -1));
1402 }
1403 else if(v.iszero())
1404 {
1405 // The value of v is zero and *this is non-zero.
1406 return (neg ? -1 : 1);
1407 }
1408 else
1409 {
1410 // Both *this and v are non-zero.
1411
1412 if(neg != v.neg)
1413 {
1414 // The signs are different.
1415 return (neg ? -1 : 1);
1416 }
1417 else if(exp != v.exp)
1418 {
1419 // The signs are the same and the exponents are different.
1420 const int val_cexpression = ((exp < v.exp) ? 1 : -1);
1421
1422 return (neg ? val_cexpression : -val_cexpression);
1423 }
1424 else
1425 {
1426 // The signs are the same and the exponents are the same.
1427 // Compare the data.
1428 const int val_cmp_data = cmp_data(v.data);
1429
1430 return ((!neg) ? val_cmp_data : -val_cmp_data);
1431 }
1432 }
1433}
1434
1435template <unsigned Digits10, class ExponentType, class Allocator>
1436bool cpp_dec_float<Digits10, ExponentType, Allocator>::isone() const
1437{
1438 // Check if the value of *this is identically 1 or very close to 1.
1439
1440 const bool not_negative_and_is_finite = ((!neg) && (isfinite)());
1441
1442 if(not_negative_and_is_finite)
1443 {
1444 if((data[0u] == static_cast<boost::uint32_t>(1u)) && (exp == static_cast<ExponentType>(0)))
1445 {
1446 const typename array_type::const_iterator it_non_zero = std::find_if(data.begin(), data.end(), data_elem_is_non_zero_predicate);
1447 return (it_non_zero == data.end());
1448 }
1449 else if((data[0u] == static_cast<boost::uint32_t>(cpp_dec_float_elem_mask - 1)) && (exp == static_cast<ExponentType>(-cpp_dec_float_elem_digits10)))
1450 {
1451 const typename array_type::const_iterator it_non_nine = std::find_if(data.begin(), data.end(), data_elem_is_non_nine_predicate);
1452 return (it_non_nine == data.end());
1453 }
1454 }
1455
1456 return false;
1457}
1458
1459template <unsigned Digits10, class ExponentType, class Allocator>
1460bool cpp_dec_float<Digits10, ExponentType, Allocator>::isint() const
1461{
1462 if(fpclass != cpp_dec_float_finite) { return false; }
1463
1464 if(iszero()) { return true; }
1465
1466 if(exp < static_cast<ExponentType>(0)) { return false; } // |*this| < 1.
1467
1468 const typename array_type::size_type offset_decimal_part = static_cast<typename array_type::size_type>(exp / cpp_dec_float_elem_digits10) + 1u;
1469
1470 if(offset_decimal_part >= static_cast<typename array_type::size_type>(cpp_dec_float_elem_number))
1471 {
1472 // The number is too large to resolve the integer part.
1473 // It considered to be a pure integer.
1474 return true;
1475 }
1476
1477 typename array_type::const_iterator it_non_zero = std::find_if(data.begin() + offset_decimal_part, data.end(), data_elem_is_non_zero_predicate);
1478
1479 return (it_non_zero == data.end());
1480}
1481
1482template <unsigned Digits10, class ExponentType, class Allocator>
1483void cpp_dec_float<Digits10, ExponentType, Allocator>::extract_parts(double& mantissa, ExponentType& exponent) const
1484{
1485 // Extract the approximate parts mantissa and base-10 exponent from the input cpp_dec_float<Digits10, ExponentType, Allocator> value x.
1486
1487 // Extracts the mantissa and exponent.
1488 exponent = exp;
1489
1490 boost::uint32_t p10 = static_cast<boost::uint32_t>(1u);
1491 boost::uint32_t test = data[0u];
1492
1493 for(;;)
1494 {
1495 test /= static_cast<boost::uint32_t>(10u);
1496
1497 if(test == static_cast<boost::uint32_t>(0u))
1498 {
1499 break;
1500 }
1501
1502 p10 *= static_cast<boost::uint32_t>(10u);
1503 ++exponent;
1504 }
1505
1506 // Establish the upper bound of limbs for extracting the double.
1507 const int max_elem_in_double_count = static_cast<int>(static_cast<boost::int32_t>(std::numeric_limits<double>::digits10) / cpp_dec_float_elem_digits10)
1508 + (static_cast<int>(static_cast<boost::int32_t>(std::numeric_limits<double>::digits10) % cpp_dec_float_elem_digits10) != 0 ? 1 : 0)
1509 + 1;
1510
1511 // And make sure this upper bound stays within bounds of the elems.
1512 const std::size_t max_elem_extract_count = static_cast<std::size_t>((std::min)(static_cast<boost::int32_t>(max_elem_in_double_count), cpp_dec_float_elem_number));
1513
1514 // Extract into the mantissa the first limb, extracted as a double.
1515 mantissa = static_cast<double>(data[0]);
1516 double scale = 1.0;
1517
1518 // Extract the rest of the mantissa piecewise from the limbs.
1519 for(std::size_t i = 1u; i < max_elem_extract_count; i++)
1520 {
1521 scale /= static_cast<double>(cpp_dec_float_elem_mask);
1522 mantissa += (static_cast<double>(data[i]) * scale);
1523 }
1524
1525 mantissa /= static_cast<double>(p10);
1526
1527 if(neg) { mantissa = -mantissa; }
1528}
1529
1530template <unsigned Digits10, class ExponentType, class Allocator>
1531double cpp_dec_float<Digits10, ExponentType, Allocator>::extract_double() const
1532{
1533 // Returns the double conversion of a cpp_dec_float<Digits10, ExponentType, Allocator>.
1534
1535 // Check for non-normal cpp_dec_float<Digits10, ExponentType, Allocator>.
1536 if(!(isfinite)())
1537 {
1538 if((isnan)())
1539 {
1540 return std::numeric_limits<double>::quiet_NaN();
1541 }
1542 else
1543 {
1544 return ((!neg) ? std::numeric_limits<double>::infinity()
1545 : -std::numeric_limits<double>::infinity());
1546 }
1547 }
1548
1549 cpp_dec_float<Digits10, ExponentType, Allocator> xx(*this);
1550 if(xx.isneg())
1551 xx.negate();
1552
1553 // Check if *this cpp_dec_float<Digits10, ExponentType, Allocator> is zero.
1554 if(iszero() || (xx.compare(double_min()) < 0))
1555 {
1556 return 0.0;
1557 }
1558
1559 // Check if *this cpp_dec_float<Digits10, ExponentType, Allocator> exceeds the maximum of double.
1560 if(xx.compare(double_max()) > 0)
1561 {
1562 return ((!neg) ? std::numeric_limits<double>::infinity()
1563 : -std::numeric_limits<double>::infinity());
1564 }
1565
1566 std::stringstream ss;
1567
1568 ss << str(std::numeric_limits<double>::digits10 + (2 + 1), std::ios_base::scientific);
1569
1570 double d;
1571 ss >> d;
1572
1573 return d;
1574}
1575
1576template <unsigned Digits10, class ExponentType, class Allocator>
1577long double cpp_dec_float<Digits10, ExponentType, Allocator>::extract_long_double() const
1578{
1579 // Returns the long double conversion of a cpp_dec_float<Digits10, ExponentType, Allocator>.
1580
1581 // Check if *this cpp_dec_float<Digits10, ExponentType, Allocator> is subnormal.
1582 if(!(isfinite)())
1583 {
1584 if((isnan)())
1585 {
1586 return std::numeric_limits<long double>::quiet_NaN();
1587 }
1588 else
1589 {
1590 return ((!neg) ? std::numeric_limits<long double>::infinity()
1591 : -std::numeric_limits<long double>::infinity());
1592 }
1593 }
1594
1595 cpp_dec_float<Digits10, ExponentType, Allocator> xx(*this);
1596 if(xx.isneg())
1597 xx.negate();
1598
1599 // Check if *this cpp_dec_float<Digits10, ExponentType, Allocator> is zero.
1600 if(iszero() || (xx.compare(long_double_min()) < 0))
1601 {
1602 return static_cast<long double>(0.0);
1603 }
1604
1605 // Check if *this cpp_dec_float<Digits10, ExponentType, Allocator> exceeds the maximum of double.
1606 if(xx.compare(long_double_max()) > 0)
1607 {
1608 return ((!neg) ? std::numeric_limits<long double>::infinity()
1609 : -std::numeric_limits<long double>::infinity());
1610 }
1611
1612 std::stringstream ss;
1613
1614 ss << str(std::numeric_limits<long double>::digits10 + (2 + 1), std::ios_base::scientific);
1615
1616 long double ld;
1617 ss >> ld;
1618
1619 return ld;
1620}
1621
1622template <unsigned Digits10, class ExponentType, class Allocator>
1623boost::long_long_type cpp_dec_float<Digits10, ExponentType, Allocator>::extract_signed_long_long() const
1624{
1625 // Extracts a signed long long from *this.
1626 // If (x > maximum of long long) or (x < minimum of long long),
1627 // then the maximum or minimum of long long is returned accordingly.
1628
1629 if(exp < static_cast<ExponentType>(0))
1630 {
1631 return static_cast<boost::long_long_type>(0);
1632 }
1633
1634 const bool b_neg = isneg();
1635
1636 boost::ulong_long_type val;
1637
1638 if((!b_neg) && (compare(long_long_max()) > 0))
1639 {
1640 return (std::numeric_limits<boost::long_long_type>::max)();
1641 }
1642 else if(b_neg && (compare(long_long_min()) < 0))
1643 {
1644 return (std::numeric_limits<boost::long_long_type>::min)();
1645 }
1646 else
1647 {
1648 // Extract the data into an boost::ulong_long_type value.
1649 cpp_dec_float<Digits10, ExponentType, Allocator> xn(extract_integer_part());
1650 if(xn.isneg())
1651 xn.negate();
1652
1653 val = static_cast<boost::ulong_long_type>(xn.data[0]);
1654
1655 const boost::int32_t imax = (std::min)(static_cast<boost::int32_t>(static_cast<boost::int32_t>(xn.exp) / cpp_dec_float_elem_digits10), static_cast<boost::int32_t>(cpp_dec_float_elem_number - static_cast<boost::int32_t>(1)));
1656
1657 for(boost::int32_t i = static_cast<boost::int32_t>(1); i <= imax; i++)
1658 {
1659 val *= static_cast<boost::ulong_long_type>(cpp_dec_float_elem_mask);
1660 val += static_cast<boost::ulong_long_type>(xn.data[i]);
1661 }
1662 }
1663
1664 if (!b_neg)
1665 {
1666 return static_cast<boost::long_long_type>(val);
1667 }
1668 else
1669 {
1670 // This strange expression avoids a hardware trap in the corner case
1671 // that val is the most negative value permitted in boost::long_long_type.
1672 // See https://svn.boost.org/trac/boost/ticket/9740.
1673 //
1674 boost::long_long_type sval = static_cast<boost::long_long_type>(val - 1);
1675 sval = -sval;
1676 --sval;
1677 return sval;
1678 }
1679}
1680
1681template <unsigned Digits10, class ExponentType, class Allocator>
1682boost::ulong_long_type cpp_dec_float<Digits10, ExponentType, Allocator>::extract_unsigned_long_long() const
1683{
1684 // Extracts an boost::ulong_long_type from *this.
1685 // If x exceeds the maximum of boost::ulong_long_type,
1686 // then the maximum of boost::ulong_long_type is returned.
1687 // If x is negative, then the boost::ulong_long_type cast of
1688 // the long long extracted value is returned.
1689
1690 if(isneg())
1691 {
1692 return static_cast<boost::ulong_long_type>(extract_signed_long_long());
1693 }
1694
1695 if(exp < static_cast<ExponentType>(0))
1696 {
1697 return static_cast<boost::ulong_long_type>(0u);
1698 }
1699
1700 const cpp_dec_float<Digits10, ExponentType, Allocator> xn(extract_integer_part());
1701
1702 boost::ulong_long_type val;
1703
1704 if(xn.compare(ulong_long_max()) > 0)
1705 {
1706 return (std::numeric_limits<boost::ulong_long_type>::max)();
1707 }
1708 else
1709 {
1710 // Extract the data into an boost::ulong_long_type value.
1711 val = static_cast<boost::ulong_long_type>(xn.data[0]);
1712
1713 const boost::int32_t imax = (std::min)(static_cast<boost::int32_t>(static_cast<boost::int32_t>(xn.exp) / cpp_dec_float_elem_digits10), static_cast<boost::int32_t>(cpp_dec_float_elem_number - static_cast<boost::int32_t>(1)));
1714
1715 for(boost::int32_t i = static_cast<boost::int32_t>(1); i <= imax; i++)
1716 {
1717 val *= static_cast<boost::ulong_long_type>(cpp_dec_float_elem_mask);
1718 val += static_cast<boost::ulong_long_type>(xn.data[i]);
1719 }
1720 }
1721
1722 return val;
1723}
1724
1725template <unsigned Digits10, class ExponentType, class Allocator>
1726cpp_dec_float<Digits10, ExponentType, Allocator> cpp_dec_float<Digits10, ExponentType, Allocator>::extract_integer_part() const
1727{
1728 // Compute the signed integer part of x.
1729
1730 if(!(isfinite)())
1731 {
1732 return *this;
1733 }
1734
1735 if(exp < static_cast<ExponentType>(0))
1736 {
1737 // The absolute value of the number is smaller than 1.
1738 // Thus the integer part is zero.
1739 return zero();
1740 }
1741
1742 // Truncate the digits from the decimal part, including guard digits
1743 // that do not belong to the integer part.
1744
1745 // Make a local copy.
1746 cpp_dec_float<Digits10, ExponentType, Allocator> x = *this;
1747
1748 // Clear out the decimal portion
1749 const size_t first_clear = (static_cast<size_t>(x.exp) / static_cast<size_t>(cpp_dec_float_elem_digits10)) + 1u;
1750 const size_t last_clear = static_cast<size_t>(cpp_dec_float_elem_number);
1751
1752 if(first_clear < last_clear)
1753 std::fill(x.data.begin() + first_clear, x.data.begin() + last_clear, static_cast<boost::uint32_t>(0u));
1754
1755 return x;
1756}
1757
1758template <unsigned Digits10, class ExponentType, class Allocator>
1759std::string cpp_dec_float<Digits10, ExponentType, Allocator>::str(boost::intmax_t number_of_digits, std::ios_base::fmtflags f) const
1760{
1761 if((this->isinf)())
1762 {
1763 if(this->isneg())
1764 return "-inf";
1765 else if(f & std::ios_base::showpos)
1766 return "+inf";
1767 else
1768 return "inf";
1769 }
1770 else if((this->isnan)())
1771 {
1772 return "nan";
1773 }
1774
1775 std::string str;
1776 boost::intmax_t org_digits(number_of_digits);
1777 ExponentType my_exp = order();
1778
1779 if(number_of_digits == 0)
1780 number_of_digits = cpp_dec_float_total_digits10;
1781
1782 if(f & std::ios_base::fixed)
1783 {
1784 number_of_digits += my_exp + 1;
1785 }
1786 else if(f & std::ios_base::scientific)
1787 ++number_of_digits;
1788 // Determine the number of elements needed to provide the requested digits from cpp_dec_float<Digits10, ExponentType, Allocator>.
1789 const std::size_t number_of_elements = (std::min)(static_cast<std::size_t>((number_of_digits / static_cast<std::size_t>(cpp_dec_float_elem_digits10)) + 2u),
1790 static_cast<std::size_t>(cpp_dec_float_elem_number));
1791
1792 // Extract the remaining digits from cpp_dec_float<Digits10, ExponentType, Allocator> after the decimal point.
1793 str = boost::lexical_cast<std::string>(data[0]);
1794
1795 // Extract all of the digits from cpp_dec_float<Digits10, ExponentType, Allocator>, beginning with the first data element.
1796 for(std::size_t i = static_cast<std::size_t>(1u); i < number_of_elements; i++)
1797 {
1798 std::stringstream ss;
1799
1800 ss << std::setw(static_cast<std::streamsize>(cpp_dec_float_elem_digits10))
1801 << std::setfill(static_cast<char>('0'))
1802 << data[i];
1803
1804 str += ss.str();
1805 }
1806
1807 bool have_leading_zeros = false;
1808
1809 if(number_of_digits == 0)
1810 {
1811 // We only get here if the output format is "fixed" and we just need to
1812 // round the first non-zero digit.
1813 number_of_digits -= my_exp + 1; // reset to original value
1814 str.insert(static_cast<std::string::size_type>(0), std::string::size_type(number_of_digits), '0');
1815 have_leading_zeros = true;
1816 }
1817
1818 if(number_of_digits < 0)
1819 {
1820 str = "0";
1821 if(isneg())
1822 str.insert(static_cast<std::string::size_type>(0), 1, '-');
1823 boost::multiprecision::detail::format_float_string(str, 0, number_of_digits - my_exp - 1, f, this->iszero());
1824 return str;
1825 }
1826 else
1827 {
1828 // Cut the output to the size of the precision.
1829 if(str.length() > static_cast<std::string::size_type>(number_of_digits))
1830 {
1831 // Get the digit after the last needed digit for rounding
1832 const boost::uint32_t round = static_cast<boost::uint32_t>(static_cast<boost::uint32_t>(str[static_cast<std::string::size_type>(number_of_digits)]) - static_cast<boost::uint32_t>('0'));
1833
1834 bool need_round_up = round >= 5u;
1835
1836 if(round == 5u)
1837 {
1838 const boost::uint32_t ix = static_cast<boost::uint32_t>(static_cast<boost::uint32_t>(str[static_cast<std::string::size_type>(number_of_digits - 1)]) - static_cast<boost::uint32_t>('0'));
1839 if((ix & 1u) == 0)
1840 {
1841 // We have an even digit followed by a 5, so we might not actually need to round up
1842 // if all the remaining digits are zero:
1843 if(str.find_first_not_of('0', static_cast<std::string::size_type>(number_of_digits + 1)) == std::string::npos)
1844 {
1845 bool all_zeros = true;
1846 // No none-zero trailing digits in the string, now check whatever parts we didn't convert to the string:
1847 for(std::size_t i = number_of_elements; i < data.size(); i++)
1848 {
1849 if(data[i])
1850 {
1851 all_zeros = false;
1852 break;
1853 }
1854 }
1855 if(all_zeros)
1856 need_round_up = false; // tie break - round to even.
1857 }
1858 }
1859 }
1860
1861 // Truncate the string
1862 str.erase(static_cast<std::string::size_type>(number_of_digits));
1863
1864 if(need_round_up)
1865 {
1866 std::size_t ix = static_cast<std::size_t>(str.length() - 1u);
1867
1868 // Every trailing 9 must be rounded up
1869 while(ix && (static_cast<boost::int32_t>(str.at(ix)) - static_cast<boost::int32_t>('0') == static_cast<boost::int32_t>(9)))
1870 {
1871 str.at(ix) = static_cast<char>('0');
1872 --ix;
1873 }
1874
1875 if(!ix)
1876 {
1877 // There were nothing but trailing nines.
1878 if(static_cast<boost::int32_t>(static_cast<boost::int32_t>(str.at(ix)) - static_cast<boost::int32_t>(0x30)) == static_cast<boost::int32_t>(9))
1879 {
1880 // Increment up to the next order and adjust exponent.
1881 str.at(ix) = static_cast<char>('1');
1882 ++my_exp;
1883 }
1884 else
1885 {
1886 // Round up this digit.
1887 ++str.at(ix);
1888 }
1889 }
1890 else
1891 {
1892 // Round up the last digit.
1893 ++str[ix];
1894 }
1895 }
1896 }
1897 }
1898
1899 if(have_leading_zeros)
1900 {
1901 // We need to take the zeros back out again, and correct the exponent
1902 // if we rounded up:
1903 if(str[std::string::size_type(number_of_digits - 1)] != '0')
1904 {
1905 ++my_exp;
1906 str.erase(0, std::string::size_type(number_of_digits - 1));
1907 }
1908 else
1909 str.erase(0, std::string::size_type(number_of_digits));
1910 }
1911
1912 if(isneg())
1913 str.insert(static_cast<std::string::size_type>(0), 1, '-');
1914
1915 boost::multiprecision::detail::format_float_string(str, my_exp, org_digits, f, this->iszero());
1916 return str;
1917}
1918
1919template <unsigned Digits10, class ExponentType, class Allocator>
1920bool cpp_dec_float<Digits10, ExponentType, Allocator>::rd_string(const char* const s)
1921{
1922#ifndef BOOST_NO_EXCEPTIONS
1923 try{
1924#endif
1925
1926 std::string str(s);
1927
1928 // TBD: Using several regular expressions may significantly reduce
1929 // the code complexity (and perhaps the run-time) of rd_string().
1930
1931 // Get a possible exponent and remove it.
1932 exp = static_cast<ExponentType>(0);
1933
1934 std::size_t pos;
1935
1936 if( ((pos = str.find('e')) != std::string::npos)
1937 || ((pos = str.find('E')) != std::string::npos)
1938 )
1939 {
1940 // Remove the exponent part from the string.
1941 exp = boost::lexical_cast<ExponentType>(static_cast<const char*>(str.c_str() + (pos + 1u)));
1942 str = str.substr(static_cast<std::size_t>(0u), pos);
1943 }
1944
1945 // Get a possible +/- sign and remove it.
1946 neg = false;
1947
1948 if(str.size())
1949 {
1950 if(str[0] == '-')
1951 {
1952 neg = true;
1953 str.erase(0, 1);
1954 }
1955 else if(str[0] == '+')
1956 {
1957 str.erase(0, 1);
1958 }
1959 }
1960 //
1961 // Special cases for infinities and NaN's:
1962 //
1963 if((str == "inf") || (str == "INF") || (str == "infinity") || (str == "INFINITY"))
1964 {
1965 if(neg)
1966 {
1967 *this = this->inf();
1968 this->negate();
1969 }
1970 else
1971 *this = this->inf();
1972 return true;
1973 }
1974 if((str.size() >= 3) && ((str.substr(0, 3) == "nan") || (str.substr(0, 3) == "NAN") || (str.substr(0, 3) == "NaN")))
1975 {
1976 *this = this->nan();
1977 return true;
1978 }
1979
1980 // Remove the leading zeros for all input types.
1981 const std::string::iterator fwd_it_leading_zero = std::find_if(str.begin(), str.end(), char_is_nonzero_predicate);
1982
1983 if(fwd_it_leading_zero != str.begin())
1984 {
1985 if(fwd_it_leading_zero == str.end())
1986 {
1987 // The string contains nothing but leading zeros.
1988 // This string represents zero.
1989 operator=(zero());
1990 return true;
1991 }
1992 else
1993 {
1994 str.erase(str.begin(), fwd_it_leading_zero);
1995 }
1996 }
1997
1998 // Put the input string into the standard cpp_dec_float<Digits10, ExponentType, Allocator> input form
1999 // aaa.bbbbE+/-n, where aaa has 1...cpp_dec_float_elem_digits10, bbbb has an
2000 // even multiple of cpp_dec_float_elem_digits10 which are possibly zero padded
2001 // on the right-end, and n is a signed 64-bit integer which is an
2002 // even multiple of cpp_dec_float_elem_digits10.
2003
2004 // Find a possible decimal point.
2005 pos = str.find(static_cast<char>('.'));
2006
2007 if(pos != std::string::npos)
2008 {
2009 // Remove all trailing insignificant zeros.
2010 const std::string::const_reverse_iterator rit_non_zero = std::find_if(str.rbegin(), str.rend(), char_is_nonzero_predicate);
2011
2012 if(rit_non_zero != static_cast<std::string::const_reverse_iterator>(str.rbegin()))
2013 {
2014 const std::string::size_type ofs = str.length() - std::distance<std::string::const_reverse_iterator>(str.rbegin(), rit_non_zero);
2015 str.erase(str.begin() + ofs, str.end());
2016 }
2017
2018 // Check if the input is identically zero.
2019 if(str == std::string("."))
2020 {
2021 operator=(zero());
2022 return true;
2023 }
2024
2025 // Remove leading significant zeros just after the decimal point
2026 // and adjust the exponent accordingly.
2027 // Note that the while-loop operates only on strings of the form ".000abcd..."
2028 // and peels away the zeros just after the decimal point.
2029 if(str.at(static_cast<std::size_t>(0u)) == static_cast<char>('.'))
2030 {
2031 const std::string::iterator it_non_zero = std::find_if(str.begin() + 1u, str.end(), char_is_nonzero_predicate);
2032
2033 std::size_t delta_exp = static_cast<std::size_t>(0u);
2034
2035 if(str.at(static_cast<std::size_t>(1u)) == static_cast<char>('0'))
2036 {
2037 delta_exp = std::distance<std::string::const_iterator>(str.begin() + 1u, it_non_zero);
2038 }
2039
2040 // Bring one single digit into the mantissa and adjust the exponent accordingly.
2041 str.erase(str.begin(), it_non_zero);
2042 str.insert(static_cast<std::string::size_type>(1u), ".");
2043 exp -= static_cast<ExponentType>(delta_exp + 1u);
2044 }
2045 }
2046 else
2047 {
2048 // Input string has no decimal point: Append decimal point.
2049 str.append(".");
2050 }
2051
2052 // Shift the decimal point such that the exponent is an even multiple of cpp_dec_float_elem_digits10.
2053 std::size_t n_shift = static_cast<std::size_t>(0u);
2054 const std::size_t n_exp_rem = static_cast<std::size_t>(exp % static_cast<ExponentType>(cpp_dec_float_elem_digits10));
2055
2056 if((exp % static_cast<ExponentType>(cpp_dec_float_elem_digits10)) != static_cast<ExponentType>(0))
2057 {
2058 n_shift = ((exp < static_cast<ExponentType>(0))
2059 ? static_cast<std::size_t>(n_exp_rem + static_cast<std::size_t>(cpp_dec_float_elem_digits10))
2060 : static_cast<std::size_t>(n_exp_rem));
2061 }
2062
2063 // Make sure that there are enough digits for the decimal point shift.
2064 pos = str.find(static_cast<char>('.'));
2065
2066 std::size_t pos_plus_one = static_cast<std::size_t>(pos + 1u);
2067
2068 if((str.length() - pos_plus_one) < n_shift)
2069 {
2070 const std::size_t sz = static_cast<std::size_t>(n_shift - (str.length() - pos_plus_one));
2071
2072 str.append(std::string(sz, static_cast<char>('0')));
2073 }
2074
2075 // Do the decimal point shift.
2076 if(n_shift != static_cast<std::size_t>(0u))
2077 {
2078 str.insert(static_cast<std::string::size_type>(pos_plus_one + n_shift), ".");
2079
2080 str.erase(pos, static_cast<std::string::size_type>(1u));
2081
2082 exp -= static_cast<ExponentType>(n_shift);
2083 }
2084
2085 // Cut the size of the mantissa to <= cpp_dec_float_elem_digits10.
2086 pos = str.find(static_cast<char>('.'));
2087 pos_plus_one = static_cast<std::size_t>(pos + 1u);
2088
2089 if(pos > static_cast<std::size_t>(cpp_dec_float_elem_digits10))
2090 {
2091 const boost::int32_t n_pos = static_cast<boost::int32_t>(pos);
2092 const boost::int32_t n_rem_is_zero = ((static_cast<boost::int32_t>(n_pos % cpp_dec_float_elem_digits10) == static_cast<boost::int32_t>(0)) ? static_cast<boost::int32_t>(1) : static_cast<boost::int32_t>(0));
2093 const boost::int32_t n = static_cast<boost::int32_t>(static_cast<boost::int32_t>(n_pos / cpp_dec_float_elem_digits10) - n_rem_is_zero);
2094
2095 str.insert(static_cast<std::size_t>(static_cast<boost::int32_t>(n_pos - static_cast<boost::int32_t>(n * cpp_dec_float_elem_digits10))), ".");
2096
2097 str.erase(pos_plus_one, static_cast<std::size_t>(1u));
2098
2099 exp += static_cast<ExponentType>(static_cast<ExponentType>(n) * static_cast<ExponentType>(cpp_dec_float_elem_digits10));
2100 }
2101
2102 // Pad the decimal part such that its value is an even
2103 // multiple of cpp_dec_float_elem_digits10.
2104 pos = str.find(static_cast<char>('.'));
2105 pos_plus_one = static_cast<std::size_t>(pos + 1u);
2106
2107 const boost::int32_t n_dec = static_cast<boost::int32_t>(static_cast<boost::int32_t>(str.length() - 1u) - static_cast<boost::int32_t>(pos));
2108 const boost::int32_t n_rem = static_cast<boost::int32_t>(n_dec % cpp_dec_float_elem_digits10);
2109
2110 boost::int32_t n_cnt = ((n_rem != static_cast<boost::int32_t>(0))
2111 ? static_cast<boost::int32_t>(cpp_dec_float_elem_digits10 - n_rem)
2112 : static_cast<boost::int32_t>(0));
2113
2114 if(n_cnt != static_cast<boost::int32_t>(0))
2115 {
2116 str.append(static_cast<std::size_t>(n_cnt), static_cast<char>('0'));
2117 }
2118
2119 // Truncate decimal part if it is too long.
2120 const std::size_t max_dec = static_cast<std::size_t>((cpp_dec_float_elem_number - 1) * cpp_dec_float_elem_digits10);
2121
2122 if(static_cast<std::size_t>(str.length() - pos) > max_dec)
2123 {
2124 str = str.substr(static_cast<std::size_t>(0u),
2125 static_cast<std::size_t>(pos_plus_one + max_dec));
2126 }
2127
2128 // Now the input string has the standard cpp_dec_float<Digits10, ExponentType, Allocator> input form.
2129 // (See the comment above.)
2130
2131 // Set all the data elements to 0.
2132 std::fill(data.begin(), data.end(), static_cast<boost::uint32_t>(0u));
2133
2134 // Extract the data.
2135
2136 // First get the digits to the left of the decimal point...
2137 data[0u] = boost::lexical_cast<boost::uint32_t>(str.substr(static_cast<std::size_t>(0u), pos));
2138
2139 // ...then get the remaining digits to the right of the decimal point.
2140 const std::string::size_type i_end = ((str.length() - pos_plus_one) / static_cast<std::string::size_type>(cpp_dec_float_elem_digits10));
2141
2142 for(std::string::size_type i = static_cast<std::string::size_type>(0u); i < i_end; i++)
2143 {
2144 const std::string::const_iterator it = str.begin()
2145 + pos_plus_one
2146 + (i * static_cast<std::string::size_type>(cpp_dec_float_elem_digits10));
2147
2148 data[i + 1u] = boost::lexical_cast<boost::uint32_t>(std::string(it, it + static_cast<std::string::size_type>(cpp_dec_float_elem_digits10)));
2149 }
2150
2151 // Check for overflow...
2152 if(exp > cpp_dec_float_max_exp10)
2153 {
2154 const bool b_result_is_neg = neg;
2155
2156 *this = inf();
2157 if(b_result_is_neg)
2158 negate();
2159 }
2160
2161 // ...and check for underflow.
2162 if(exp <= cpp_dec_float_min_exp10)
2163 {
2164 if(exp == cpp_dec_float_min_exp10)
2165 {
2166 // Check for identity with the minimum value.
2167 cpp_dec_float<Digits10, ExponentType, Allocator> test = *this;
2168
2169 test.exp = static_cast<ExponentType>(0);
2170
2171 if(test.isone())
2172 {
2173 *this = zero();
2174 }
2175 }
2176 else
2177 {
2178 *this = zero();
2179 }
2180 }
2181
2182#ifndef BOOST_NO_EXCEPTIONS
2183 }
2184 catch(const bad_lexical_cast&)
2185 {
2186 // Rethrow with better error message:
2187 std::string msg = "Unable to parse the string \"";
2188 msg += s;
2189 msg += "\" as a floating point value.";
2190 throw std::runtime_error(msg);
2191 }
2192#endif
2193 return true;
2194}
2195
2196template <unsigned Digits10, class ExponentType, class Allocator>
2197cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float(const double mantissa, const ExponentType exponent)
2198 : data (),
2199 exp (static_cast<ExponentType>(0)),
2200 neg (false),
2201 fpclass (cpp_dec_float_finite),
2202 prec_elem(cpp_dec_float_elem_number)
2203{
2204 // Create *this cpp_dec_float<Digits10, ExponentType, Allocator> from a given mantissa and exponent.
2205 // Note: This constructor does not maintain the full precision of double.
2206
2207 const bool mantissa_is_iszero = (::fabs(mantissa) < ((std::numeric_limits<double>::min)() * (1.0 + std::numeric_limits<double>::epsilon())));
2208
2209 if(mantissa_is_iszero)
2210 {
2211 std::fill(data.begin(), data.end(), static_cast<boost::uint32_t>(0u));
2212 return;
2213 }
2214
2215 const bool b_neg = (mantissa < 0.0);
2216
2217 double d = ((!b_neg) ? mantissa : -mantissa);
2218 ExponentType e = exponent;
2219
2220 while(d > 10.0) { d /= 10.0; ++e; }
2221 while(d < 1.0) { d *= 10.0; --e; }
2222
2223 boost::int32_t shift = static_cast<boost::int32_t>(e % static_cast<boost::int32_t>(cpp_dec_float_elem_digits10));
2224
2225 while(static_cast<boost::int32_t>(shift-- % cpp_dec_float_elem_digits10) != static_cast<boost::int32_t>(0))
2226 {
2227 d *= 10.0;
2228 --e;
2229 }
2230
2231 exp = e;
2232 neg = b_neg;
2233
2234 std::fill(data.begin(), data.end(), static_cast<boost::uint32_t>(0u));
2235
2236 static const boost::int32_t digit_ratio = static_cast<boost::int32_t>(static_cast<boost::int32_t>(std::numeric_limits<double>::digits10) / static_cast<boost::int32_t>(cpp_dec_float_elem_digits10));
2237 static const boost::int32_t digit_loops = static_cast<boost::int32_t>(digit_ratio + static_cast<boost::int32_t>(2));
2238
2239 for(boost::int32_t i = static_cast<boost::int32_t>(0); i < digit_loops; i++)
2240 {
2241 boost::uint32_t n = static_cast<boost::uint32_t>(static_cast<boost::uint64_t>(d));
2242 data[i] = static_cast<boost::uint32_t>(n);
2243 d -= static_cast<double>(n);
2244 d *= static_cast<double>(cpp_dec_float_elem_mask);
2245 }
2246}
2247
2248template <unsigned Digits10, class ExponentType, class Allocator>
2249cpp_dec_float<Digits10, ExponentType, Allocator>& cpp_dec_float<Digits10, ExponentType, Allocator>::operator= (long double a)
2250{
2251 // Christopher Kormanyos's original code used a cast to boost::long_long_type here, but that fails
2252 // when long double has more digits than a boost::long_long_type.
2253 using std::frexp;
2254 using std::ldexp;
2255 using std::floor;
2256
2257 if(a == 0)
2258 return *this = zero();
2259
2260 if(a == 1)
2261 return *this = one();
2262
2263 if((boost::math::isinf)(a))
2264 {
2265 *this = inf();
2266 if(a < 0)
2267 this->negate();
2268 return *this;
2269 }
2270
2271 if((boost::math::isnan)(a))
2272 return *this = nan();
2273
2274 int e;
2275 long double f, term;
2276 *this = zero();
2277
2278 f = frexp(a, &e);
2279 // See https://svn.boost.org/trac/boost/ticket/10924 for an example of why this may go wrong:
2280 BOOST_ASSERT((boost::math::isfinite)(f));
2281
2282 static const int shift = std::numeric_limits<int>::digits - 1;
2283
2284 while(f)
2285 {
2286 // extract int sized bits from f:
2287 f = ldexp(f, shift);
2288 BOOST_ASSERT((boost::math::isfinite)(f));
2289 term = floor(f);
2290 e -= shift;
2291 *this *= pow2(shift);
2292 if(term > 0)
2293 add_unsigned_long_long(static_cast<unsigned>(term));
2294 else
2295 sub_unsigned_long_long(static_cast<unsigned>(-term));
2296 f -= term;
2297 }
2298
2299 if(e != 0)
2300 *this *= pow2(e);
2301
2302 return *this;
2303}
2304
2305template <unsigned Digits10, class ExponentType, class Allocator>
2306void cpp_dec_float<Digits10, ExponentType, Allocator>::from_unsigned_long_long(const boost::ulong_long_type u)
2307{
2308 std::fill(data.begin(), data.end(), static_cast<boost::uint32_t>(0u));
2309
2310 exp = static_cast<ExponentType>(0);
2311 neg = false;
2312 fpclass = cpp_dec_float_finite;
2313 prec_elem = cpp_dec_float_elem_number;
2314
2315 std::size_t i =static_cast<std::size_t>(0u);
2316
2317 boost::ulong_long_type uu = u;
2318
2319 boost::uint32_t temp[(std::numeric_limits<boost::ulong_long_type>::digits10 / static_cast<int>(cpp_dec_float_elem_digits10)) + 3] = { static_cast<boost::uint32_t>(0u) };
2320
2321 while(uu != static_cast<boost::ulong_long_type>(0u))
2322 {
2323 temp[i] = static_cast<boost::uint32_t>(uu % static_cast<boost::ulong_long_type>(cpp_dec_float_elem_mask));
2324 uu = static_cast<boost::ulong_long_type>(uu / static_cast<boost::ulong_long_type>(cpp_dec_float_elem_mask));
2325 ++i;
2326 }
2327
2328 if(i > static_cast<std::size_t>(1u))
2329 {
2330 exp += static_cast<ExponentType>((i - 1u) * static_cast<std::size_t>(cpp_dec_float_elem_digits10));
2331 }
2332
2333 std::reverse(temp, temp + i);
2334 std::copy(temp, temp + (std::min)(i, static_cast<std::size_t>(cpp_dec_float_elem_number)), data.begin());
2335}
2336
2337template <unsigned Digits10, class ExponentType, class Allocator>
2338boost::uint32_t cpp_dec_float<Digits10, ExponentType, Allocator>::mul_loop_uv(boost::uint32_t* const u, const boost::uint32_t* const v, const boost::int32_t p)
2339{
2340 //
2341 // There is a limit on how many limbs this algorithm can handle without dropping digits
2342 // due to overflow in the carry, it is:
2343 //
2344 // FLOOR( (2^64 - 1) / (10^8 * 10^8) ) == 1844
2345 //
2346 BOOST_STATIC_ASSERT_MSG(cpp_dec_float_elem_number < 1800, "Too many limbs in the data type for the multiplication algorithm - unsupported precision in cpp_dec_float.");
2347
2348 boost::uint64_t carry = static_cast<boost::uint64_t>(0u);
2349
2350 for(boost::int32_t j = static_cast<boost::int32_t>(p - 1u); j >= static_cast<boost::int32_t>(0); j--)
2351 {
2352 boost::uint64_t sum = carry;
2353
2354 for(boost::int32_t i = j; i >= static_cast<boost::int32_t>(0); i--)
2355 {
2356 sum += static_cast<boost::uint64_t>(u[j - i] * static_cast<boost::uint64_t>(v[i]));
2357 }
2358
2359 u[j] = static_cast<boost::uint32_t>(sum % static_cast<boost::uint32_t>(cpp_dec_float_elem_mask));
2360 carry = static_cast<boost::uint64_t>(sum / static_cast<boost::uint32_t>(cpp_dec_float_elem_mask));
2361 }
2362
2363 return static_cast<boost::uint32_t>(carry);
2364}
2365
2366template <unsigned Digits10, class ExponentType, class Allocator>
2367boost::uint32_t cpp_dec_float<Digits10, ExponentType, Allocator>::mul_loop_n(boost::uint32_t* const u, boost::uint32_t n, const boost::int32_t p)
2368{
2369 boost::uint64_t carry = static_cast<boost::uint64_t>(0u);
2370
2371 // Multiplication loop.
2372 for(boost::int32_t j = p - 1; j >= static_cast<boost::int32_t>(0); j--)
2373 {
2374 const boost::uint64_t t = static_cast<boost::uint64_t>(carry + static_cast<boost::uint64_t>(u[j] * static_cast<boost::uint64_t>(n)));
2375 carry = static_cast<boost::uint64_t>(t / static_cast<boost::uint32_t>(cpp_dec_float_elem_mask));
2376 u[j] = static_cast<boost::uint32_t>(t - static_cast<boost::uint64_t>(static_cast<boost::uint32_t>(cpp_dec_float_elem_mask) * static_cast<boost::uint64_t>(carry)));
2377 }
2378
2379 return static_cast<boost::uint32_t>(carry);
2380}
2381
2382template <unsigned Digits10, class ExponentType, class Allocator>
2383boost::uint32_t cpp_dec_float<Digits10, ExponentType, Allocator>::div_loop_n(boost::uint32_t* const u, boost::uint32_t n, const boost::int32_t p)
2384{
2385 boost::uint64_t prev = static_cast<boost::uint64_t>(0u);
2386
2387 for(boost::int32_t j = static_cast<boost::int32_t>(0); j < p; j++)
2388 {
2389 const boost::uint64_t t = static_cast<boost::uint64_t>(u[j] + static_cast<boost::uint64_t>(prev * static_cast<boost::uint32_t>(cpp_dec_float_elem_mask)));
2390 u[j] = static_cast<boost::uint32_t>(t / n);
2391 prev = static_cast<boost::uint64_t>(t - static_cast<boost::uint64_t>(n * static_cast<boost::uint64_t>(u[j])));
2392 }
2393
2394 return static_cast<boost::uint32_t>(prev);
2395}
2396
2397template <unsigned Digits10, class ExponentType, class Allocator>
2398cpp_dec_float<Digits10, ExponentType, Allocator> cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(const boost::long_long_type p)
2399{
2400 // Create a static const table of p^2 for -128 < p < +128.
2401 // Note: The size of this table must be odd-numbered and
2402 // symmetric about 0.
2403 init.do_nothing();
2404 static const boost::array<cpp_dec_float<Digits10, ExponentType, Allocator>, 255u> p2_data =
2405 {{
2406 cpp_dec_float("5.877471754111437539843682686111228389093327783860437607543758531392086297273635864257812500000000000e-39"),
2407 cpp_dec_float("1.175494350822287507968736537222245677818665556772087521508751706278417259454727172851562500000000000e-38"),
2408 cpp_dec_float("2.350988701644575015937473074444491355637331113544175043017503412556834518909454345703125000000000000e-38"),
2409 cpp_dec_float("4.701977403289150031874946148888982711274662227088350086035006825113669037818908691406250000000000000e-38"),
2410 cpp_dec_float("9.403954806578300063749892297777965422549324454176700172070013650227338075637817382812500000000000000e-38"),
2411 cpp_dec_float("1.880790961315660012749978459555593084509864890835340034414002730045467615127563476562500000000000000e-37"),
2412 cpp_dec_float("3.761581922631320025499956919111186169019729781670680068828005460090935230255126953125000000000000000e-37"),
2413 cpp_dec_float("7.523163845262640050999913838222372338039459563341360137656010920181870460510253906250000000000000000e-37"),
2414 cpp_dec_float("1.504632769052528010199982767644474467607891912668272027531202184036374092102050781250000000000000000e-36"),
2415 cpp_dec_float("3.009265538105056020399965535288948935215783825336544055062404368072748184204101562500000000000000000e-36"),
2416 cpp_dec_float("6.018531076210112040799931070577897870431567650673088110124808736145496368408203125000000000000000000e-36"),
2417 cpp_dec_float("1.203706215242022408159986214115579574086313530134617622024961747229099273681640625000000000000000000e-35"),
2418 cpp_dec_float("2.407412430484044816319972428231159148172627060269235244049923494458198547363281250000000000000000000e-35"),
2419 cpp_dec_float("4.814824860968089632639944856462318296345254120538470488099846988916397094726562500000000000000000000e-35"),
2420 cpp_dec_float("9.629649721936179265279889712924636592690508241076940976199693977832794189453125000000000000000000000e-35"),
2421 cpp_dec_float("1.925929944387235853055977942584927318538101648215388195239938795566558837890625000000000000000000000e-34"),
2422 cpp_dec_float("3.851859888774471706111955885169854637076203296430776390479877591133117675781250000000000000000000000e-34"),
2423 cpp_dec_float("7.703719777548943412223911770339709274152406592861552780959755182266235351562500000000000000000000000e-34"),
2424 cpp_dec_float("1.540743955509788682444782354067941854830481318572310556191951036453247070312500000000000000000000000e-33"),
2425 cpp_dec_float("3.081487911019577364889564708135883709660962637144621112383902072906494140625000000000000000000000000e-33"),
2426 cpp_dec_float("6.162975822039154729779129416271767419321925274289242224767804145812988281250000000000000000000000000e-33"),
2427 cpp_dec_float("1.232595164407830945955825883254353483864385054857848444953560829162597656250000000000000000000000000e-32"),
2428 cpp_dec_float("2.465190328815661891911651766508706967728770109715696889907121658325195312500000000000000000000000000e-32"),
2429 cpp_dec_float("4.930380657631323783823303533017413935457540219431393779814243316650390625000000000000000000000000000e-32"),
2430 cpp_dec_float("9.860761315262647567646607066034827870915080438862787559628486633300781250000000000000000000000000000e-32"),
2431 cpp_dec_float("1.972152263052529513529321413206965574183016087772557511925697326660156250000000000000000000000000000e-31"),
2432 cpp_dec_float("3.944304526105059027058642826413931148366032175545115023851394653320312500000000000000000000000000000e-31"),
2433 cpp_dec_float("7.888609052210118054117285652827862296732064351090230047702789306640625000000000000000000000000000000e-31"),
2434 cpp_dec_float("1.577721810442023610823457130565572459346412870218046009540557861328125000000000000000000000000000000e-30"),
2435 cpp_dec_float("3.155443620884047221646914261131144918692825740436092019081115722656250000000000000000000000000000000e-30"),
2436 cpp_dec_float("6.310887241768094443293828522262289837385651480872184038162231445312500000000000000000000000000000000e-30"),
2437 cpp_dec_float("1.262177448353618888658765704452457967477130296174436807632446289062500000000000000000000000000000000e-29"),
2438 cpp_dec_float("2.524354896707237777317531408904915934954260592348873615264892578125000000000000000000000000000000000e-29"),
2439 cpp_dec_float("5.048709793414475554635062817809831869908521184697747230529785156250000000000000000000000000000000000e-29"),
2440 cpp_dec_float("1.009741958682895110927012563561966373981704236939549446105957031250000000000000000000000000000000000e-28"),
2441 cpp_dec_float("2.019483917365790221854025127123932747963408473879098892211914062500000000000000000000000000000000000e-28"),
2442 cpp_dec_float("4.038967834731580443708050254247865495926816947758197784423828125000000000000000000000000000000000000e-28"),
2443 cpp_dec_float("8.077935669463160887416100508495730991853633895516395568847656250000000000000000000000000000000000000e-28"),
2444 cpp_dec_float("1.615587133892632177483220101699146198370726779103279113769531250000000000000000000000000000000000000e-27"),
2445 cpp_dec_float("3.231174267785264354966440203398292396741453558206558227539062500000000000000000000000000000000000000e-27"),
2446 cpp_dec_float("6.462348535570528709932880406796584793482907116413116455078125000000000000000000000000000000000000000e-27"),
2447 cpp_dec_float("1.292469707114105741986576081359316958696581423282623291015625000000000000000000000000000000000000000e-26"),
2448 cpp_dec_float("2.584939414228211483973152162718633917393162846565246582031250000000000000000000000000000000000000000e-26"),
2449 cpp_dec_float("5.169878828456422967946304325437267834786325693130493164062500000000000000000000000000000000000000000e-26"),
2450 cpp_dec_float("1.033975765691284593589260865087453566957265138626098632812500000000000000000000000000000000000000000e-25"),
2451 cpp_dec_float("2.067951531382569187178521730174907133914530277252197265625000000000000000000000000000000000000000000e-25"),
2452 cpp_dec_float("4.135903062765138374357043460349814267829060554504394531250000000000000000000000000000000000000000000e-25"),
2453 cpp_dec_float("8.271806125530276748714086920699628535658121109008789062500000000000000000000000000000000000000000000e-25"),
2454 cpp_dec_float("1.654361225106055349742817384139925707131624221801757812500000000000000000000000000000000000000000000e-24"),
2455 cpp_dec_float("3.308722450212110699485634768279851414263248443603515625000000000000000000000000000000000000000000000e-24"),
2456 cpp_dec_float("6.617444900424221398971269536559702828526496887207031250000000000000000000000000000000000000000000000e-24"),
2457 cpp_dec_float("1.323488980084844279794253907311940565705299377441406250000000000000000000000000000000000000000000000e-23"),
2458 cpp_dec_float("2.646977960169688559588507814623881131410598754882812500000000000000000000000000000000000000000000000e-23"),
2459 cpp_dec_float("5.293955920339377119177015629247762262821197509765625000000000000000000000000000000000000000000000000e-23"),
2460 cpp_dec_float("1.058791184067875423835403125849552452564239501953125000000000000000000000000000000000000000000000000e-22"),
2461 cpp_dec_float("2.117582368135750847670806251699104905128479003906250000000000000000000000000000000000000000000000000e-22"),
2462 cpp_dec_float("4.235164736271501695341612503398209810256958007812500000000000000000000000000000000000000000000000000e-22"),
2463 cpp_dec_float("8.470329472543003390683225006796419620513916015625000000000000000000000000000000000000000000000000000e-22"),
2464 cpp_dec_float("1.694065894508600678136645001359283924102783203125000000000000000000000000000000000000000000000000000e-21"),
2465 cpp_dec_float("3.388131789017201356273290002718567848205566406250000000000000000000000000000000000000000000000000000e-21"),
2466 cpp_dec_float("6.776263578034402712546580005437135696411132812500000000000000000000000000000000000000000000000000000e-21"),
2467 cpp_dec_float("1.355252715606880542509316001087427139282226562500000000000000000000000000000000000000000000000000000e-20"),
2468 cpp_dec_float("2.710505431213761085018632002174854278564453125000000000000000000000000000000000000000000000000000000e-20"),
2469 cpp_dec_float("5.421010862427522170037264004349708557128906250000000000000000000000000000000000000000000000000000000e-20"),
2470 cpp_dec_float("1.084202172485504434007452800869941711425781250000000000000000000000000000000000000000000000000000000e-19"),
2471 cpp_dec_float("2.168404344971008868014905601739883422851562500000000000000000000000000000000000000000000000000000000e-19"),
2472 cpp_dec_float("4.336808689942017736029811203479766845703125000000000000000000000000000000000000000000000000000000000e-19"),
2473 cpp_dec_float("8.673617379884035472059622406959533691406250000000000000000000000000000000000000000000000000000000000e-19"),
2474 cpp_dec_float("1.734723475976807094411924481391906738281250000000000000000000000000000000000000000000000000000000000e-18"),
2475 cpp_dec_float("3.469446951953614188823848962783813476562500000000000000000000000000000000000000000000000000000000000e-18"),
2476 cpp_dec_float("6.938893903907228377647697925567626953125000000000000000000000000000000000000000000000000000000000000e-18"),
2477 cpp_dec_float("1.387778780781445675529539585113525390625000000000000000000000000000000000000000000000000000000000000e-17"),
2478 cpp_dec_float("2.775557561562891351059079170227050781250000000000000000000000000000000000000000000000000000000000000e-17"),
2479 cpp_dec_float("5.551115123125782702118158340454101562500000000000000000000000000000000000000000000000000000000000000e-17"),
2480 cpp_dec_float("1.110223024625156540423631668090820312500000000000000000000000000000000000000000000000000000000000000e-16"),
2481 cpp_dec_float("2.220446049250313080847263336181640625000000000000000000000000000000000000000000000000000000000000000e-16"),
2482 cpp_dec_float("4.440892098500626161694526672363281250000000000000000000000000000000000000000000000000000000000000000e-16"),
2483 cpp_dec_float("8.881784197001252323389053344726562500000000000000000000000000000000000000000000000000000000000000000e-16"),
2484 cpp_dec_float("1.776356839400250464677810668945312500000000000000000000000000000000000000000000000000000000000000000e-15"),
2485 cpp_dec_float("3.552713678800500929355621337890625000000000000000000000000000000000000000000000000000000000000000000e-15"),
2486 cpp_dec_float("7.105427357601001858711242675781250000000000000000000000000000000000000000000000000000000000000000000e-15"),
2487 cpp_dec_float("1.421085471520200371742248535156250000000000000000000000000000000000000000000000000000000000000000000e-14"),
2488 cpp_dec_float("2.842170943040400743484497070312500000000000000000000000000000000000000000000000000000000000000000000e-14"),
2489 cpp_dec_float("5.684341886080801486968994140625000000000000000000000000000000000000000000000000000000000000000000000e-14"),
2490 cpp_dec_float("1.136868377216160297393798828125000000000000000000000000000000000000000000000000000000000000000000000e-13"),
2491 cpp_dec_float("2.273736754432320594787597656250000000000000000000000000000000000000000000000000000000000000000000000e-13"),
2492 cpp_dec_float("4.547473508864641189575195312500000000000000000000000000000000000000000000000000000000000000000000000e-13"),
2493 cpp_dec_float("9.094947017729282379150390625000000000000000000000000000000000000000000000000000000000000000000000000e-13"),
2494 cpp_dec_float("1.818989403545856475830078125000000000000000000000000000000000000000000000000000000000000000000000000e-12"),
2495 cpp_dec_float("3.637978807091712951660156250000000000000000000000000000000000000000000000000000000000000000000000000e-12"),
2496 cpp_dec_float("7.275957614183425903320312500000000000000000000000000000000000000000000000000000000000000000000000000e-12"),
2497 cpp_dec_float("1.455191522836685180664062500000000000000000000000000000000000000000000000000000000000000000000000000e-11"),
2498 cpp_dec_float("2.910383045673370361328125000000000000000000000000000000000000000000000000000000000000000000000000000e-11"),
2499 cpp_dec_float("5.820766091346740722656250000000000000000000000000000000000000000000000000000000000000000000000000000e-11"),
2500 cpp_dec_float("1.164153218269348144531250000000000000000000000000000000000000000000000000000000000000000000000000000e-10"),
2501 cpp_dec_float("2.328306436538696289062500000000000000000000000000000000000000000000000000000000000000000000000000000e-10"),
2502 cpp_dec_float("4.656612873077392578125000000000000000000000000000000000000000000000000000000000000000000000000000000e-10"),
2503 cpp_dec_float("9.313225746154785156250000000000000000000000000000000000000000000000000000000000000000000000000000000e-10"),
2504 cpp_dec_float("1.862645149230957031250000000000000000000000000000000000000000000000000000000000000000000000000000000e-9"),
2505 cpp_dec_float("3.725290298461914062500000000000000000000000000000000000000000000000000000000000000000000000000000000e-9"),
2506 cpp_dec_float("7.450580596923828125000000000000000000000000000000000000000000000000000000000000000000000000000000000e-9"),
2507 cpp_dec_float("1.490116119384765625000000000000000000000000000000000000000000000000000000000000000000000000000000000e-8"),
2508 cpp_dec_float("2.980232238769531250000000000000000000000000000000000000000000000000000000000000000000000000000000000e-8"),
2509 cpp_dec_float("5.960464477539062500000000000000000000000000000000000000000000000000000000000000000000000000000000000e-8"),
2510 cpp_dec_float("1.192092895507812500000000000000000000000000000000000000000000000000000000000000000000000000000000000e-7"),
2511 cpp_dec_float("2.384185791015625000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-7"),
2512 cpp_dec_float("4.768371582031250000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-7"),
2513 cpp_dec_float("9.536743164062500000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-7"),
2514 cpp_dec_float("1.907348632812500000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-6"),
2515 cpp_dec_float("3.814697265625000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-6"),
2516 cpp_dec_float("7.629394531250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-6"),
2517 cpp_dec_float("0.000015258789062500000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2518 cpp_dec_float("0.000030517578125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2519 cpp_dec_float("0.000061035156250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2520 cpp_dec_float("0.000122070312500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2521 cpp_dec_float("0.000244140625000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2522 cpp_dec_float("0.000488281250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2523 cpp_dec_float("0.000976562500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2524 cpp_dec_float("0.001953125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2525 cpp_dec_float("0.003906250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2526 cpp_dec_float("0.007812500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2527 cpp_dec_float("0.01562500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2528 cpp_dec_float("0.03125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2529 cpp_dec_float("0.06250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
2530 cpp_dec_float("0.125"),
2531 cpp_dec_float("0.25"),
2532 cpp_dec_float("0.5"),
2533 one(),
2534 two(),
2535 cpp_dec_float(static_cast<boost::ulong_long_type>(4)),
2536 cpp_dec_float(static_cast<boost::ulong_long_type>(8)),
2537 cpp_dec_float(static_cast<boost::ulong_long_type>(16)),
2538 cpp_dec_float(static_cast<boost::ulong_long_type>(32)),
2539 cpp_dec_float(static_cast<boost::ulong_long_type>(64)),
2540 cpp_dec_float(static_cast<boost::ulong_long_type>(128)),
2541 cpp_dec_float(static_cast<boost::ulong_long_type>(256)),
2542 cpp_dec_float(static_cast<boost::ulong_long_type>(512)),
2543 cpp_dec_float(static_cast<boost::ulong_long_type>(1024)),
2544 cpp_dec_float(static_cast<boost::ulong_long_type>(2048)),
2545 cpp_dec_float(static_cast<boost::ulong_long_type>(4096)),
2546 cpp_dec_float(static_cast<boost::ulong_long_type>(8192)),
2547 cpp_dec_float(static_cast<boost::ulong_long_type>(16384)),
2548 cpp_dec_float(static_cast<boost::ulong_long_type>(32768)),
2549 cpp_dec_float(static_cast<boost::ulong_long_type>(65536)),
2550 cpp_dec_float(static_cast<boost::ulong_long_type>(131072)),
2551 cpp_dec_float(static_cast<boost::ulong_long_type>(262144)),
2552 cpp_dec_float(static_cast<boost::ulong_long_type>(524288)),
2553 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 20u)),
2554 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 21u)),
2555 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 22u)),
2556 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 23u)),
2557 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 24u)),
2558 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 25u)),
2559 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 26u)),
2560 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 27u)),
2561 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 28u)),
2562 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 29u)),
2563 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 30u)),
2564 cpp_dec_float(static_cast<boost::uint64_t>(1uL << 31u)),
2565 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 32u)),
2566 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 33u)),
2567 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 34u)),
2568 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 35u)),
2569 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 36u)),
2570 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 37u)),
2571 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 38u)),
2572 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 39u)),
2573 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 40u)),
2574 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 41u)),
2575 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 42u)),
2576 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 43u)),
2577 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 44u)),
2578 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 45u)),
2579 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 46u)),
2580 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 47u)),
2581 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 48u)),
2582 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 49u)),
2583 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 50u)),
2584 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 51u)),
2585 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 52u)),
2586 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 53u)),
2587 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 54u)),
2588 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 55u)),
2589 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 56u)),
2590 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 57u)),
2591 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 58u)),
2592 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 59u)),
2593 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 60u)),
2594 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 61u)),
2595 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 62u)),
2596 cpp_dec_float(static_cast<boost::uint64_t>(1uLL << 63u)),
2597 cpp_dec_float("1.844674407370955161600000000000000000000000000000000000000000000000000000000000000000000000000000000e19"),
2598 cpp_dec_float("3.689348814741910323200000000000000000000000000000000000000000000000000000000000000000000000000000000e19"),
2599 cpp_dec_float("7.378697629483820646400000000000000000000000000000000000000000000000000000000000000000000000000000000e19"),
2600 cpp_dec_float("1.475739525896764129280000000000000000000000000000000000000000000000000000000000000000000000000000000e20"),
2601 cpp_dec_float("2.951479051793528258560000000000000000000000000000000000000000000000000000000000000000000000000000000e20"),
2602 cpp_dec_float("5.902958103587056517120000000000000000000000000000000000000000000000000000000000000000000000000000000e20"),
2603 cpp_dec_float("1.180591620717411303424000000000000000000000000000000000000000000000000000000000000000000000000000000e21"),
2604 cpp_dec_float("2.361183241434822606848000000000000000000000000000000000000000000000000000000000000000000000000000000e21"),
2605 cpp_dec_float("4.722366482869645213696000000000000000000000000000000000000000000000000000000000000000000000000000000e21"),
2606 cpp_dec_float("9.444732965739290427392000000000000000000000000000000000000000000000000000000000000000000000000000000e21"),
2607 cpp_dec_float("1.888946593147858085478400000000000000000000000000000000000000000000000000000000000000000000000000000e22"),
2608 cpp_dec_float("3.777893186295716170956800000000000000000000000000000000000000000000000000000000000000000000000000000e22"),
2609 cpp_dec_float("7.555786372591432341913600000000000000000000000000000000000000000000000000000000000000000000000000000e22"),
2610 cpp_dec_float("1.511157274518286468382720000000000000000000000000000000000000000000000000000000000000000000000000000e23"),
2611 cpp_dec_float("3.022314549036572936765440000000000000000000000000000000000000000000000000000000000000000000000000000e23"),
2612 cpp_dec_float("6.044629098073145873530880000000000000000000000000000000000000000000000000000000000000000000000000000e23"),
2613 cpp_dec_float("1.208925819614629174706176000000000000000000000000000000000000000000000000000000000000000000000000000e24"),
2614 cpp_dec_float("2.417851639229258349412352000000000000000000000000000000000000000000000000000000000000000000000000000e24"),
2615 cpp_dec_float("4.835703278458516698824704000000000000000000000000000000000000000000000000000000000000000000000000000e24"),
2616 cpp_dec_float("9.671406556917033397649408000000000000000000000000000000000000000000000000000000000000000000000000000e24"),
2617 cpp_dec_float("1.934281311383406679529881600000000000000000000000000000000000000000000000000000000000000000000000000e25"),
2618 cpp_dec_float("3.868562622766813359059763200000000000000000000000000000000000000000000000000000000000000000000000000e25"),
2619 cpp_dec_float("7.737125245533626718119526400000000000000000000000000000000000000000000000000000000000000000000000000e25"),
2620 cpp_dec_float("1.547425049106725343623905280000000000000000000000000000000000000000000000000000000000000000000000000e26"),
2621 cpp_dec_float("3.094850098213450687247810560000000000000000000000000000000000000000000000000000000000000000000000000e26"),
2622 cpp_dec_float("6.189700196426901374495621120000000000000000000000000000000000000000000000000000000000000000000000000e26"),
2623 cpp_dec_float("1.237940039285380274899124224000000000000000000000000000000000000000000000000000000000000000000000000e27"),
2624 cpp_dec_float("2.475880078570760549798248448000000000000000000000000000000000000000000000000000000000000000000000000e27"),
2625 cpp_dec_float("4.951760157141521099596496896000000000000000000000000000000000000000000000000000000000000000000000000e27"),
2626 cpp_dec_float("9.903520314283042199192993792000000000000000000000000000000000000000000000000000000000000000000000000e27"),
2627 cpp_dec_float("1.980704062856608439838598758400000000000000000000000000000000000000000000000000000000000000000000000e28"),
2628 cpp_dec_float("3.961408125713216879677197516800000000000000000000000000000000000000000000000000000000000000000000000e28"),
2629 cpp_dec_float("7.922816251426433759354395033600000000000000000000000000000000000000000000000000000000000000000000000e28"),
2630 cpp_dec_float("1.584563250285286751870879006720000000000000000000000000000000000000000000000000000000000000000000000e29"),
2631 cpp_dec_float("3.169126500570573503741758013440000000000000000000000000000000000000000000000000000000000000000000000e29"),
2632 cpp_dec_float("6.338253001141147007483516026880000000000000000000000000000000000000000000000000000000000000000000000e29"),
2633 cpp_dec_float("1.267650600228229401496703205376000000000000000000000000000000000000000000000000000000000000000000000e30"),
2634 cpp_dec_float("2.535301200456458802993406410752000000000000000000000000000000000000000000000000000000000000000000000e30"),
2635 cpp_dec_float("5.070602400912917605986812821504000000000000000000000000000000000000000000000000000000000000000000000e30"),
2636 cpp_dec_float("1.014120480182583521197362564300800000000000000000000000000000000000000000000000000000000000000000000e31"),
2637 cpp_dec_float("2.028240960365167042394725128601600000000000000000000000000000000000000000000000000000000000000000000e31"),
2638 cpp_dec_float("4.056481920730334084789450257203200000000000000000000000000000000000000000000000000000000000000000000e31"),
2639 cpp_dec_float("8.112963841460668169578900514406400000000000000000000000000000000000000000000000000000000000000000000e31"),
2640 cpp_dec_float("1.622592768292133633915780102881280000000000000000000000000000000000000000000000000000000000000000000e32"),
2641 cpp_dec_float("3.245185536584267267831560205762560000000000000000000000000000000000000000000000000000000000000000000e32"),
2642 cpp_dec_float("6.490371073168534535663120411525120000000000000000000000000000000000000000000000000000000000000000000e32"),
2643 cpp_dec_float("1.298074214633706907132624082305024000000000000000000000000000000000000000000000000000000000000000000e33"),
2644 cpp_dec_float("2.596148429267413814265248164610048000000000000000000000000000000000000000000000000000000000000000000e33"),
2645 cpp_dec_float("5.192296858534827628530496329220096000000000000000000000000000000000000000000000000000000000000000000e33"),
2646 cpp_dec_float("1.038459371706965525706099265844019200000000000000000000000000000000000000000000000000000000000000000e34"),
2647 cpp_dec_float("2.076918743413931051412198531688038400000000000000000000000000000000000000000000000000000000000000000e34"),
2648 cpp_dec_float("4.153837486827862102824397063376076800000000000000000000000000000000000000000000000000000000000000000e34"),
2649 cpp_dec_float("8.307674973655724205648794126752153600000000000000000000000000000000000000000000000000000000000000000e34"),
2650 cpp_dec_float("1.661534994731144841129758825350430720000000000000000000000000000000000000000000000000000000000000000e35"),
2651 cpp_dec_float("3.323069989462289682259517650700861440000000000000000000000000000000000000000000000000000000000000000e35"),
2652 cpp_dec_float("6.646139978924579364519035301401722880000000000000000000000000000000000000000000000000000000000000000e35"),
2653 cpp_dec_float("1.329227995784915872903807060280344576000000000000000000000000000000000000000000000000000000000000000e36"),
2654 cpp_dec_float("2.658455991569831745807614120560689152000000000000000000000000000000000000000000000000000000000000000e36"),
2655 cpp_dec_float("5.316911983139663491615228241121378304000000000000000000000000000000000000000000000000000000000000000e36"),
2656 cpp_dec_float("1.063382396627932698323045648224275660800000000000000000000000000000000000000000000000000000000000000e37"),
2657 cpp_dec_float("2.126764793255865396646091296448551321600000000000000000000000000000000000000000000000000000000000000e37"),
2658 cpp_dec_float("4.253529586511730793292182592897102643200000000000000000000000000000000000000000000000000000000000000e37"),
2659 cpp_dec_float("8.507059173023461586584365185794205286400000000000000000000000000000000000000000000000000000000000000e37"),
2660 cpp_dec_float("1.701411834604692317316873037158841057280000000000000000000000000000000000000000000000000000000000000e38")
2661 }};
2662
2663 if((p > static_cast<boost::long_long_type>(-128)) && (p < static_cast<boost::long_long_type>(+128)))
2664 {
2665 return p2_data[static_cast<std::size_t>(p + ((p2_data.size() - 1u) / 2u))];
2666 }
2667 else
2668 {
2669 // Compute and return 2^p.
2670 if(p < static_cast<boost::long_long_type>(0))
2671 {
2672 return pow2(static_cast<boost::long_long_type>(-p)).calculate_inv();
2673 }
2674 else
2675 {
2676 cpp_dec_float<Digits10, ExponentType, Allocator> t;
2677 default_ops::detail::pow_imp(t, two(), p, mpl::true_());
2678 return t;
2679 }
2680 }
2681}
2682
2683
2684template <unsigned Digits10, class ExponentType, class Allocator>
2685inline void eval_add(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& o)
2686{
2687 result += o;
2688}
2689template <unsigned Digits10, class ExponentType, class Allocator>
2690inline void eval_subtract(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& o)
2691{
2692 result -= o;
2693}
2694template <unsigned Digits10, class ExponentType, class Allocator>
2695inline void eval_multiply(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& o)
2696{
2697 result *= o;
2698}
2699template <unsigned Digits10, class ExponentType, class Allocator>
2700inline void eval_divide(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& o)
2701{
2702 result /= o;
2703}
2704
2705template <unsigned Digits10, class ExponentType, class Allocator>
2706inline void eval_add(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const boost::ulong_long_type& o)
2707{
2708 result.add_unsigned_long_long(o);
2709}
2710template <unsigned Digits10, class ExponentType, class Allocator>
2711inline void eval_subtract(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const boost::ulong_long_type& o)
2712{
2713 result.sub_unsigned_long_long(o);
2714}
2715template <unsigned Digits10, class ExponentType, class Allocator>
2716inline void eval_multiply(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const boost::ulong_long_type& o)
2717{
2718 result.mul_unsigned_long_long(o);
2719}
2720template <unsigned Digits10, class ExponentType, class Allocator>
2721inline void eval_divide(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const boost::ulong_long_type& o)
2722{
2723 result.div_unsigned_long_long(o);
2724}
2725
2726template <unsigned Digits10, class ExponentType, class Allocator>
2727inline void eval_add(cpp_dec_float<Digits10, ExponentType, Allocator>& result, boost::long_long_type o)
2728{
2729 if(o < 0)
2730 result.sub_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(o));
2731 else
2732 result.add_unsigned_long_long(o);
2733}
2734template <unsigned Digits10, class ExponentType, class Allocator>
2735inline void eval_subtract(cpp_dec_float<Digits10, ExponentType, Allocator>& result, boost::long_long_type o)
2736{
2737 if(o < 0)
2738 result.add_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(o));
2739 else
2740 result.sub_unsigned_long_long(o);
2741}
2742template <unsigned Digits10, class ExponentType, class Allocator>
2743inline void eval_multiply(cpp_dec_float<Digits10, ExponentType, Allocator>& result, boost::long_long_type o)
2744{
2745 if(o < 0)
2746 {
2747 result.mul_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(o));
2748 result.negate();
2749 }
2750 else
2751 result.mul_unsigned_long_long(o);
2752}
2753template <unsigned Digits10, class ExponentType, class Allocator>
2754inline void eval_divide(cpp_dec_float<Digits10, ExponentType, Allocator>& result, boost::long_long_type o)
2755{
2756 if(o < 0)
2757 {
2758 result.div_unsigned_long_long(boost::multiprecision::detail::unsigned_abs(o));
2759 result.negate();
2760 }
2761 else
2762 result.div_unsigned_long_long(o);
2763}
2764
2765template <unsigned Digits10, class ExponentType, class Allocator>
2766inline void eval_convert_to(boost::ulong_long_type* result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
2767{
2768 *result = val.extract_unsigned_long_long();
2769}
2770template <unsigned Digits10, class ExponentType, class Allocator>
2771inline void eval_convert_to(boost::long_long_type* result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
2772{
2773 *result = val.extract_signed_long_long();
2774}
2775template <unsigned Digits10, class ExponentType, class Allocator>
2776inline void eval_convert_to(long double* result, cpp_dec_float<Digits10, ExponentType, Allocator>& val)
2777{
2778 *result = val.extract_long_double();
2779}
2780
2781//
2782// Non member function support:
2783//
2784template <unsigned Digits10, class ExponentType, class Allocator>
2785inline int eval_fpclassify(const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
2786{
2787 if((x.isinf)())
2788 return FP_INFINITE;
2789 if((x.isnan)())
2790 return FP_NAN;
2791 if(x.iszero())
2792 return FP_ZERO;
2793 return FP_NORMAL;
2794}
2795
2796template <unsigned Digits10, class ExponentType, class Allocator>
2797inline void eval_abs(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
2798{
2799 result = x;
2800 if(x.isneg())
2801 result.negate();
2802}
2803
2804template <unsigned Digits10, class ExponentType, class Allocator>
2805inline void eval_fabs(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
2806{
2807 result = x;
2808 if(x.isneg())
2809 result.negate();
2810}
2811
2812template <unsigned Digits10, class ExponentType, class Allocator>
2813inline void eval_sqrt(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
2814{
2815 result = x;
2816 result.calculate_sqrt();
2817}
2818
2819template <unsigned Digits10, class ExponentType, class Allocator>
2820inline void eval_floor(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
2821{
2822 result = x;
2823 if(!(x.isfinite)() || x.isint())
2824 {
2825 return;
2826 }
2827
2828 if(x.isneg())
2829 result -= cpp_dec_float<Digits10, ExponentType, Allocator>::one();
2830 result = result.extract_integer_part();
2831}
2832
2833template <unsigned Digits10, class ExponentType, class Allocator>
2834inline void eval_ceil(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
2835{
2836 result = x;
2837 if(!(x.isfinite)() || x.isint())
2838 {
2839 return;
2840 }
2841
2842 if(!x.isneg())
2843 result += cpp_dec_float<Digits10, ExponentType, Allocator>::one();
2844 result = result.extract_integer_part();
2845}
2846
2847template <unsigned Digits10, class ExponentType, class Allocator>
2848inline void eval_trunc(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x)
2849{
2850 if(!(x.isfinite)())
2851 {
2852 result = boost::math::policies::raise_rounding_error("boost::multiprecision::trunc<%1%>(%1%)", 0, number<cpp_dec_float<Digits10, ExponentType, Allocator> >(x), number<cpp_dec_float<Digits10, ExponentType, Allocator> >(x), boost::math::policies::policy<>()).backend();
2853 return;
2854 }
2855 else if(x.isint())
2856 {
2857 result = x;
2858 return;
2859 }
2860 result = x.extract_integer_part();
2861}
2862
2863template <unsigned Digits10, class ExponentType, class Allocator>
2864inline ExponentType eval_ilogb(const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
2865{
2866 // Set result, to the exponent of val:
2867 return val.order();
2868}
2869template <unsigned Digits10, class ExponentType, class Allocator, class ArgType>
2870inline void eval_scalbn(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& val, ArgType e_)
2871{
2872 using default_ops::eval_multiply;
2873 const ExponentType e = e_;
2874 cpp_dec_float<Digits10, ExponentType, Allocator> t(1.0, e);
2875 eval_multiply(result, val, t);
2876}
2877
2878template <unsigned Digits10, class ExponentType, class Allocator, class ArgType>
2879inline void eval_ldexp(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x, ArgType e)
2880{
2881 const boost::long_long_type the_exp = static_cast<boost::long_long_type>(e);
2882
2883 if((the_exp > (std::numeric_limits<ExponentType>::max)()) || (the_exp < (std::numeric_limits<ExponentType>::min)()))
2884 BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Exponent value is out of range.")));
2885
2886 result = x;
2887
2888 if ((the_exp > static_cast<boost::long_long_type>(-std::numeric_limits<boost::long_long_type>::digits)) && (the_exp < static_cast<boost::long_long_type>(0)))
2889 result.div_unsigned_long_long(1ULL << static_cast<boost::long_long_type>(-the_exp));
2890 else if((the_exp < static_cast<boost::long_long_type>( std::numeric_limits<boost::long_long_type>::digits)) && (the_exp > static_cast<boost::long_long_type>(0)))
2891 result.mul_unsigned_long_long(1ULL << the_exp);
2892 else if(the_exp != static_cast<boost::long_long_type>(0))
2893 result *= cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(e);
2894}
2895
2896template <unsigned Digits10, class ExponentType, class Allocator>
2897inline void eval_frexp(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x, ExponentType* e)
2898{
2899 result = x;
2900 if(result.isneg())
2901 result.negate();
2902
2903 if(result.iszero())
2904 {
2905 *e = 0;
2906 return;
2907 }
2908
2909 ExponentType t = result.order();
2910 BOOST_MP_USING_ABS
2911 if(abs(t) < ((std::numeric_limits<ExponentType>::max)() / 1000))
2912 {
2913 t *= 1000;
2914 t /= 301;
2915 }
2916 else
2917 {
2918 t /= 301;
2919 t *= 1000;
2920 }
2921
2922 result *= cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(-t);
2923
2924 if(result.iszero() || (result.isinf)() || (result.isnan)())
2925 {
2926 // pow2 overflowed, slip the calculation up:
2927 result = x;
2928 if(result.isneg())
2929 result.negate();
2930 t /= 2;
2931 result *= cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(-t);
2932 }
2933 BOOST_MP_USING_ABS
2934 if(abs(result.order()) > 5)
2935 {
2936 // If our first estimate doesn't get close enough then try recursion until we do:
2937 ExponentType e2;
2938 cpp_dec_float<Digits10, ExponentType, Allocator> r2;
2939 eval_frexp(r2, result, &e2);
2940 // overflow protection:
2941 if((t > 0) && (e2 > 0) && (t > (std::numeric_limits<ExponentType>::max)() - e2))
2942 BOOST_THROW_EXCEPTION(std::runtime_error("Exponent is too large to be represented as a power of 2."));
2943 if((t < 0) && (e2 < 0) && (t < (std::numeric_limits<ExponentType>::min)() - e2))
2944 BOOST_THROW_EXCEPTION(std::runtime_error("Exponent is too large to be represented as a power of 2."));
2945 t += e2;
2946 result = r2;
2947 }
2948
2949 while(result.compare(cpp_dec_float<Digits10, ExponentType, Allocator>::one()) >= 0)
2950 {
2951 result /= cpp_dec_float<Digits10, ExponentType, Allocator>::two();
2952 ++t;
2953 }
2954 while(result.compare(cpp_dec_float<Digits10, ExponentType, Allocator>::half()) < 0)
2955 {
2956 result *= cpp_dec_float<Digits10, ExponentType, Allocator>::two();
2957 --t;
2958 }
2959 *e = t;
2960 if(x.isneg())
2961 result.negate();
2962}
2963
2964template <unsigned Digits10, class ExponentType, class Allocator>
2965inline typename disable_if<is_same<ExponentType, int> >::type eval_frexp(cpp_dec_float<Digits10, ExponentType, Allocator>& result, const cpp_dec_float<Digits10, ExponentType, Allocator>& x, int* e)
2966{
2967 ExponentType t;
2968 eval_frexp(result, x, &t);
2969 if((t > (std::numeric_limits<int>::max)()) || (t < (std::numeric_limits<int>::min)()))
2970 BOOST_THROW_EXCEPTION(std::runtime_error("Exponent is outside the range of an int"));
2971 *e = static_cast<int>(t);
2972}
2973
2974template <unsigned Digits10, class ExponentType, class Allocator>
2975inline bool eval_is_zero(const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
2976{
2977 return val.iszero();
2978}
2979template <unsigned Digits10, class ExponentType, class Allocator>
2980inline int eval_get_sign(const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
2981{
2982 return val.iszero() ? 0 : val.isneg() ? -1 : 1;
2983}
2984
2985template <unsigned Digits10, class ExponentType, class Allocator>
2986inline std::size_t hash_value(const cpp_dec_float<Digits10, ExponentType, Allocator>& val)
2987{
2988 return val.hash();
2989}
2990
2991} // namespace backends
2992
2993using boost::multiprecision::backends::cpp_dec_float;
2994
2995
2996typedef number<cpp_dec_float<50> > cpp_dec_float_50;
2997typedef number<cpp_dec_float<100> > cpp_dec_float_100;
2998
2999#ifdef BOOST_NO_SFINAE_EXPR
3000
3001namespace detail{
3002
3003template<unsigned D1, class E1, class A1, unsigned D2, class E2, class A2>
3004struct is_explicitly_convertible<cpp_dec_float<D1, E1, A1>, cpp_dec_float<D2, E2, A2> > : public mpl::true_ {};
3005
3006}
3007
3008#endif
3009
3010
3011}}
3012
3013namespace std
3014{
3015 template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3016 class numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >
3017 {
3018 public:
3019 BOOST_STATIC_CONSTEXPR bool is_specialized = true;
3020 BOOST_STATIC_CONSTEXPR bool is_signed = true;
3021 BOOST_STATIC_CONSTEXPR bool is_integer = false;
3022 BOOST_STATIC_CONSTEXPR bool is_exact = false;
3023 BOOST_STATIC_CONSTEXPR bool is_bounded = true;
3024 BOOST_STATIC_CONSTEXPR bool is_modulo = false;
3025 BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
3026 BOOST_STATIC_CONSTEXPR int digits = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10;
3027 BOOST_STATIC_CONSTEXPR int digits10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10;
3028 BOOST_STATIC_CONSTEXPR int max_digits10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_total_digits10;
3029 BOOST_STATIC_CONSTEXPR ExponentType min_exponent = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp; // Type differs from int.
3030 BOOST_STATIC_CONSTEXPR ExponentType min_exponent10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_min_exp10; // Type differs from int.
3031 BOOST_STATIC_CONSTEXPR ExponentType max_exponent = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp; // Type differs from int.
3032 BOOST_STATIC_CONSTEXPR ExponentType max_exponent10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_max_exp10; // Type differs from int.
3033 BOOST_STATIC_CONSTEXPR int radix = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_radix;
3034 BOOST_STATIC_CONSTEXPR std::float_round_style round_style = std::round_indeterminate;
3035 BOOST_STATIC_CONSTEXPR bool has_infinity = true;
3036 BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = true;
3037 BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
3038 BOOST_STATIC_CONSTEXPR std::float_denorm_style has_denorm = std::denorm_absent;
3039 BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
3040 BOOST_STATIC_CONSTEXPR bool traps = false;
3041 BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
3042
3043 BOOST_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)(); }
3044 BOOST_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)(); }
3045 BOOST_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(); }
3046 BOOST_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(); }
3047 BOOST_STATIC_CONSTEXPR boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> round_error () { return 0.5L; }
3048 BOOST_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(); }
3049 BOOST_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(); }
3050 BOOST_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(); }
3051 BOOST_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>::zero(); }
3052 };
3053
3054#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
3055
3056template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3057BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::digits;
3058template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3059BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::digits10;
3060template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3061BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::max_digits10;
3062template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3063BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_signed;
3064template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3065BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_integer;
3066template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3067BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_exact;
3068template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3069BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::radix;
3070template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3071BOOST_CONSTEXPR_OR_CONST ExponentType numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::min_exponent;
3072template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3073BOOST_CONSTEXPR_OR_CONST ExponentType numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::min_exponent10;
3074template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3075BOOST_CONSTEXPR_OR_CONST ExponentType numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::max_exponent;
3076template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3077BOOST_CONSTEXPR_OR_CONST ExponentType numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::max_exponent10;
3078template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3079BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_infinity;
3080template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3081BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_quiet_NaN;
3082template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3083BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_signaling_NaN;
3084template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3085BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_denorm;
3086template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3087BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::has_denorm_loss;
3088template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3089BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_iec559;
3090template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3091BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_bounded;
3092template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3093BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::is_modulo;
3094template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3095BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::traps;
3096template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3097BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::tinyness_before;
3098template <unsigned Digits10, class ExponentType, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
3099BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates> >::round_style;
3100
3101#endif
3102}
3103
3104namespace boost{ namespace math{
3105
3106namespace policies{
3107
3108template <unsigned Digits10, class ExponentType, class Allocator, class Policy, boost::multiprecision::expression_template_option ExpressionTemplates>
3109struct precision< boost::multiprecision::number<boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>, ExpressionTemplates>, Policy>
3110{
3111 // Define a local copy of cpp_dec_float_digits10 because it might differ
3112 // from the template parameter Digits10 for small or large digit counts.
3113 static const boost::int32_t cpp_dec_float_digits10 = boost::multiprecision::cpp_dec_float<Digits10, ExponentType, Allocator>::cpp_dec_float_digits10;
3114
3115 typedef typename Policy::precision_type precision_type;
3116 typedef digits2<((cpp_dec_float_digits10 + 1LL) * 1000LL) / 301LL> digits_2;
3117 typedef typename mpl::if_c<
3118 ((digits_2::value <= precision_type::value)
3119 || (Policy::precision_type::value <= 0)),
3120 // Default case, full precision for RealType:
3121 digits_2,
3122 // User customized precision:
3123 precision_type
3124 >::type type;
3125};
3126
3127} // namespace policies
3128
3129}} // namespaces boost::math
3130
3131#ifdef BOOST_MSVC
3132#pragma warning(pop)
3133#endif
3134
3135#endif