89#define MPREAL_HAVE_MSVC_DEBUGVIEW
90#define MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS
95#define MPREAL_VERSION_MAJOR 3
96#define MPREAL_VERSION_MINOR 6
97#define MPREAL_VERSION_PATCHLEVEL 9
98#define MPREAL_VERSION_STRING "3.6.9"
101#if defined(__GNUC__) && defined(__INTEL_COMPILER)
102 #define IsInf(x) isinf(x)
104#elif defined(_MSC_VER)
105 #define IsInf(x) (!_finite(x))
108 #define IsInf(x) std::isinf(x)
113 #define __has_feature(x) 0
120#if (__has_feature(cxx_rvalue_references) || \
121 defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \
122 (defined(_MSC_VER) && _MSC_VER >= 1600) && !defined(MPREAL_DISABLE_MOVE_SEMANTIC))
124 #define MPREAL_HAVE_MOVE_SUPPORT
127 #define mpfr_is_initialized(x) (0 != (x)->_mpfr_d)
128 #define mpfr_set_uninitialized(x) ((x)->_mpfr_d = 0 )
132#if (__has_feature(cxx_explicit_conversions) || \
133 (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC_MINOR >= 5) || __cplusplus >= 201103L || \
134 (defined(_MSC_VER) && _MSC_VER >= 1800) || \
135 (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1300))
137 #define MPREAL_HAVE_EXPLICIT_CONVERTERS
140#define MPFR_USE_INTMAX_T
142#if defined(MPREAL_HAVE_MSVC_DEBUGVIEW) && defined(_MSC_VER) && defined(_DEBUG)
143 #define MPREAL_MSVC_DEBUGVIEW_CODE DebugView = toString();
144 #define MPREAL_MSVC_DEBUGVIEW_DATA std::string DebugView;
146 #define MPREAL_MSVC_DEBUGVIEW_CODE
147 #define MPREAL_MSVC_DEBUGVIEW_DATA
150#define MPFR_USE_NO_MACRO
153#if (MPFR_VERSION < MPFR_VERSION_NUM(3,0,0))
158#define MPREAL_DOUBLE_BITS_OVERFLOW -1
165#define mpfr_set_zero_fast(x) ((x)->_mpfr_exp = __MPFR_EXP_ZERO)
168 #define MPREAL_PERMISSIVE_EXPR __extension__
170 #define MPREAL_PERMISSIVE_EXPR
182 inline static mp_rnd_t
get_default_rnd() {
return (mp_rnd_t)(mpfr_get_default_rounding_mode()); }
202 mpreal(
const mpfr_t u,
bool shared =
false);
209#ifdef MPREAL_HAVE_MOVE_SUPPORT
222 mpreal& operator=(
const mpf_t v);
223 mpreal& operator=(
const mpz_t v);
224 mpreal& operator=(
const mpq_t v);
225 mpreal& operator=(
const long double v);
226 mpreal& operator=(
const double v);
227 mpreal& operator=(
const unsigned long int v);
228 mpreal& operator=(
const unsigned long long int v);
229 mpreal& operator=(
const long long int v);
230 mpreal& operator=(
const unsigned int v);
231 mpreal& operator=(
const long int v);
232 mpreal& operator=(
const int v);
233 mpreal& operator=(
const char*
s);
234 mpreal& operator=(
const std::string&
s);
235 template <
typename real_t>
mpreal& operator= (
const std::complex<real_t>& z);
239 mpreal& operator+=(
const mpf_t v);
240 mpreal& operator+=(
const mpz_t v);
241 mpreal& operator+=(
const mpq_t v);
242 mpreal& operator+=(
const long double u);
243 mpreal& operator+=(
const double u);
244 mpreal& operator+=(
const unsigned long int u);
245 mpreal& operator+=(
const unsigned int u);
246 mpreal& operator+=(
const long int u);
247 mpreal& operator+=(
const int u);
249 mpreal& operator+=(
const long long int u);
250 mpreal& operator+=(
const unsigned long long int u);
251 mpreal& operator-=(
const long long int u);
252 mpreal& operator-=(
const unsigned long long int u);
253 mpreal& operator*=(
const long long int u);
254 mpreal& operator*=(
const unsigned long long int u);
255 mpreal& operator/=(
const long long int u);
256 mpreal& operator/=(
const unsigned long long int u);
260 const mpreal operator++ (
int);
264 mpreal& operator-=(
const mpz_t v);
265 mpreal& operator-=(
const mpq_t v);
266 mpreal& operator-=(
const long double u);
267 mpreal& operator-=(
const double u);
268 mpreal& operator-=(
const unsigned long int u);
269 mpreal& operator-=(
const unsigned int u);
270 mpreal& operator-=(
const long int u);
271 mpreal& operator-=(
const int u);
279 const mpreal operator-- (
int);
283 mpreal& operator*=(
const mpz_t v);
284 mpreal& operator*=(
const mpq_t v);
285 mpreal& operator*=(
const long double v);
286 mpreal& operator*=(
const double v);
287 mpreal& operator*=(
const unsigned long int v);
288 mpreal& operator*=(
const unsigned int v);
289 mpreal& operator*=(
const long int v);
290 mpreal& operator*=(
const int v);
294 mpreal& operator/=(
const mpz_t v);
295 mpreal& operator/=(
const mpq_t v);
296 mpreal& operator/=(
const long double v);
297 mpreal& operator/=(
const double v);
298 mpreal& operator/=(
const unsigned long int v);
299 mpreal& operator/=(
const unsigned int v);
300 mpreal& operator/=(
const long int v);
301 mpreal& operator/=(
const int v);
309 mpreal& operator<<=(
const unsigned long int u);
310 mpreal& operator<<=(
const unsigned int u);
311 mpreal& operator<<=(
const long int u);
312 mpreal& operator<<=(
const int u);
315 mpreal& operator>>=(
const unsigned long int u);
316 mpreal& operator>>=(
const unsigned int u);
317 mpreal& operator>>=(
const long int u);
318 mpreal& operator>>=(
const int u);
321 bool toBool ( )
const;
322 long toLong (mp_rnd_t mode = GMP_RNDZ)
const;
323 unsigned long toULong (mp_rnd_t mode = GMP_RNDZ)
const;
324 long long toLLong (mp_rnd_t mode = GMP_RNDZ)
const;
325 unsigned long long toULLong (mp_rnd_t mode = GMP_RNDZ)
const;
326 float toFloat (mp_rnd_t mode = GMP_RNDN)
const;
327 double toDouble (mp_rnd_t mode = GMP_RNDN)
const;
328 long double toLDouble (mp_rnd_t mode = GMP_RNDN)
const;
330#if defined (MPREAL_HAVE_EXPLICIT_CONVERTERS)
331 explicit operator bool ()
const {
return toBool(); }
332 explicit operator signed char ()
const {
return (
signed char)toLong(); }
333 explicit operator unsigned char ()
const {
return (
unsigned char)
toULong(); }
334 explicit operator short ()
const {
return (
short)
toLong(); }
335 explicit operator unsigned short ()
const {
return (
unsigned short)
toULong();}
336 explicit operator int ()
const {
return (
int)
toLong(); }
337 explicit operator unsigned int ()
const {
return (
unsigned int)
toULong(); }
338 explicit operator long ()
const {
return toLong(); }
339 explicit operator unsigned long ()
const {
return toULong(); }
340 explicit operator long long ()
const {
return toLLong(); }
341 explicit operator unsigned long long ()
const {
return toULLong(); }
342 explicit operator float ()
const {
return toFloat(); }
343 explicit operator double ()
const {
return toDouble(); }
344 explicit operator long double ()
const {
return toLDouble(); }
354 std::string
toString(
int n = -1,
int b = 10, mp_rnd_t mode = mpreal::get_default_rnd())
const;
356#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
357 std::string
toString(
const std::string& format)
const;
360 std::ostream&
output(std::ostream& os)
const;
363 friend const mpreal sqr (
const mpreal& v, mp_rnd_t rnd_mode);
364 friend const mpreal sqrt(
const mpreal& v, mp_rnd_t rnd_mode);
365 friend const mpreal sqrt(
const unsigned long int v, mp_rnd_t rnd_mode);
366 friend const mpreal cbrt(
const mpreal& v, mp_rnd_t rnd_mode);
367 friend const mpreal root(
const mpreal& v,
unsigned long int k, mp_rnd_t rnd_mode);
368 friend const mpreal pow (
const mpreal& a,
const mpreal& b, mp_rnd_t rnd_mode);
369 friend const mpreal pow (
const mpreal& a,
const mpz_t b, mp_rnd_t rnd_mode);
370 friend const mpreal pow (
const mpreal& a,
const unsigned long int b, mp_rnd_t rnd_mode);
371 friend const mpreal pow (
const mpreal& a,
const long int b, mp_rnd_t rnd_mode);
372 friend const mpreal pow (
const unsigned long int a,
const mpreal& b, mp_rnd_t rnd_mode);
373 friend const mpreal pow (
const unsigned long int a,
const unsigned long int b, mp_rnd_t rnd_mode);
374 friend const mpreal fabs(
const mpreal& v, mp_rnd_t rnd_mode);
376 friend const mpreal abs(
const mpreal& v, mp_rnd_t rnd_mode);
377 friend const mpreal dim(
const mpreal& a,
const mpreal& b, mp_rnd_t rnd_mode);
378 friend inline const mpreal mul_2ui(
const mpreal& v,
unsigned long int k, mp_rnd_t rnd_mode);
379 friend inline const mpreal mul_2si(
const mpreal& v,
long int k, mp_rnd_t rnd_mode);
380 friend inline const mpreal div_2ui(
const mpreal& v,
unsigned long int k, mp_rnd_t rnd_mode);
381 friend inline const mpreal div_2si(
const mpreal& v,
long int k, mp_rnd_t rnd_mode);
382 friend int cmpabs(
const mpreal& a,
const mpreal& b);
384 friend const mpreal log (
const mpreal& v, mp_rnd_t rnd_mode);
385 friend const mpreal log2 (
const mpreal& v, mp_rnd_t rnd_mode);
386 friend const mpreal logb (
const mpreal& v, mp_rnd_t rnd_mode);
387 friend mp_exp_t
ilogb(
const mpreal& v);
388 friend const mpreal log10(
const mpreal& v, mp_rnd_t rnd_mode);
389 friend const mpreal exp (
const mpreal& v, mp_rnd_t rnd_mode);
390 friend const mpreal exp2 (
const mpreal& v, mp_rnd_t rnd_mode);
391 friend const mpreal exp10(
const mpreal& v, mp_rnd_t rnd_mode);
392 friend const mpreal log1p(
const mpreal& v, mp_rnd_t rnd_mode);
393 friend const mpreal expm1(
const mpreal& v, mp_rnd_t rnd_mode);
397 friend const mpreal cos(
const mpreal& v, mp_rnd_t rnd_mode);
398 friend const mpreal sin(
const mpreal& v, mp_rnd_t rnd_mode);
399 friend const mpreal tan(
const mpreal& v, mp_rnd_t rnd_mode);
400 friend const mpreal sec(
const mpreal& v, mp_rnd_t rnd_mode);
401 friend const mpreal csc(
const mpreal& v, mp_rnd_t rnd_mode);
402 friend const mpreal cot(
const mpreal& v, mp_rnd_t rnd_mode);
403 friend int sin_cos(mpreal&
s, mpreal& c,
const mpreal& v, mp_rnd_t rnd_mode);
405 friend const mpreal acos (
const mpreal& v, mp_rnd_t rnd_mode);
406 friend const mpreal asin (
const mpreal& v, mp_rnd_t rnd_mode);
407 friend const mpreal atan (
const mpreal& v, mp_rnd_t rnd_mode);
408 friend const mpreal atan2 (
const mpreal& y,
const mpreal&
x, mp_rnd_t rnd_mode);
409 friend const mpreal acot (
const mpreal& v, mp_rnd_t rnd_mode);
410 friend const mpreal asec (
const mpreal& v, mp_rnd_t rnd_mode);
411 friend const mpreal acsc (
const mpreal& v, mp_rnd_t rnd_mode);
413 friend const mpreal cosh (
const mpreal& v, mp_rnd_t rnd_mode);
414 friend const mpreal sinh (
const mpreal& v, mp_rnd_t rnd_mode);
415 friend const mpreal tanh (
const mpreal& v, mp_rnd_t rnd_mode);
416 friend const mpreal sech (
const mpreal& v, mp_rnd_t rnd_mode);
417 friend const mpreal csch (
const mpreal& v, mp_rnd_t rnd_mode);
418 friend const mpreal coth (
const mpreal& v, mp_rnd_t rnd_mode);
419 friend const mpreal acosh (
const mpreal& v, mp_rnd_t rnd_mode);
420 friend const mpreal asinh (
const mpreal& v, mp_rnd_t rnd_mode);
421 friend const mpreal atanh (
const mpreal& v, mp_rnd_t rnd_mode);
422 friend const mpreal acoth (
const mpreal& v, mp_rnd_t rnd_mode);
423 friend const mpreal asech (
const mpreal& v, mp_rnd_t rnd_mode);
424 friend const mpreal acsch (
const mpreal& v, mp_rnd_t rnd_mode);
426 friend const mpreal hypot (
const mpreal&
x,
const mpreal& y, mp_rnd_t rnd_mode);
428 friend const mpreal fac_ui (
unsigned long int v, mp_prec_t prec, mp_rnd_t rnd_mode);
429 friend const mpreal eint (
const mpreal& v, mp_rnd_t rnd_mode);
431 friend const mpreal gamma (
const mpreal& v, mp_rnd_t rnd_mode);
432 friend const mpreal tgamma (
const mpreal& v, mp_rnd_t rnd_mode);
433 friend const mpreal lngamma (
const mpreal& v, mp_rnd_t rnd_mode);
434 friend const mpreal lgamma (
const mpreal& v,
int *signp, mp_rnd_t rnd_mode);
435 friend const mpreal zeta (
const mpreal& v, mp_rnd_t rnd_mode);
436 friend const mpreal erf (
const mpreal& v, mp_rnd_t rnd_mode);
437 friend const mpreal erfc (
const mpreal& v, mp_rnd_t rnd_mode);
438 friend const mpreal besselj0 (
const mpreal& v, mp_rnd_t rnd_mode);
439 friend const mpreal besselj1 (
const mpreal& v, mp_rnd_t rnd_mode);
440 friend const mpreal besseljn (
long n,
const mpreal& v, mp_rnd_t rnd_mode);
441 friend const mpreal bessely0 (
const mpreal& v, mp_rnd_t rnd_mode);
442 friend const mpreal bessely1 (
const mpreal& v, mp_rnd_t rnd_mode);
443 friend const mpreal besselyn (
long n,
const mpreal& v, mp_rnd_t rnd_mode);
444 friend const mpreal fma (
const mpreal& v1,
const mpreal& v2,
const mpreal& v3, mp_rnd_t rnd_mode);
445 friend const mpreal fms (
const mpreal& v1,
const mpreal& v2,
const mpreal& v3, mp_rnd_t rnd_mode);
446 friend const mpreal agm (
const mpreal& v1,
const mpreal& v2, mp_rnd_t rnd_mode);
447 friend const mpreal sum (
const mpreal tab[],
const unsigned long int n,
int& status, mp_rnd_t rnd_mode);
448 friend int sgn (
const mpreal& v);
451#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
452 friend int sinh_cosh (mpreal&
s, mpreal& c,
const mpreal& v, mp_rnd_t rnd_mode);
453 friend const mpreal li2 (
const mpreal& v, mp_rnd_t rnd_mode);
454 friend const mpreal fmod (
const mpreal&
x,
const mpreal& y, mp_rnd_t rnd_mode);
455 friend const mpreal rec_sqrt (
const mpreal& v, mp_rnd_t rnd_mode);
458 friend const mpreal rem (
const mpreal&
x,
const mpreal& y, mp_rnd_t rnd_mode);
459 friend const mpreal mod (
const mpreal&
x,
const mpreal& y, mp_rnd_t rnd_mode);
462#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
463 friend const mpreal digamma (
const mpreal& v, mp_rnd_t rnd_mode);
464 friend const mpreal ai (
const mpreal& v, mp_rnd_t rnd_mode);
468#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,1,0))
481 friend const mpreal modf(
const mpreal& v, mpreal& n);
494 friend std::ostream&
operator<<(std::ostream& os,
const mpreal& v);
495 friend std::istream&
operator>>(std::istream& is, mpreal& v);
498 friend const mpreal rint (
const mpreal& v, mp_rnd_t rnd_mode);
502 friend long lround(
const mpreal& v);
503 friend long long llround(
const mpreal& v);
509 friend const mpreal frac (
const mpreal& v, mp_rnd_t rnd_mode);
510 friend const mpreal remainder (
const mpreal&
x,
const mpreal& y, mp_rnd_t rnd_mode);
511 friend const mpreal remquo (
const mpreal&
x,
const mpreal& y,
int* q, mp_rnd_t rnd_mode);
522#if (MPFR_VERSION <= MPFR_VERSION_NUM(2,4,2))
527 friend bool isnan (
const mpreal& v);
528 friend bool isinf (
const mpreal& v);
529 friend bool isfinite (
const mpreal& v);
535#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
600 std::string
why() {
return "inexact conversion from floating point"; }
622#ifdef MPREAL_HAVE_MOVE_SUPPORT
625 mpfr_set_uninitialized(mpfr_ptr());
626 mpfr_swap(mpfr_ptr(), other.mpfr_ptr());
631inline mpreal& mpreal::operator=(mpreal&& other)
635 mpfr_swap(mpfr_ptr(), other.mpfr_ptr());
646 std::memcpy(
mpfr_ptr(), u,
sizeof(mpfr_t));
650 mpfr_init2(
mpfr_ptr(), mpfr_get_prec(u));
659 mpfr_init2(
mpfr_ptr(),(mp_prec_t) mpf_get_prec(u));
685#if (MPREAL_DOUBLE_BITS_OVERFLOW > -1)
706inline mpreal::mpreal(
const unsigned long long int u, mp_prec_t prec, mp_rnd_t mode)
772#ifdef MPREAL_HAVE_MOVE_SUPPORT
773 if(mpfr_is_initialized(
x))
805template <
typename Rhs>
809template <
typename Lhs>
810inline const typename internal::result_type<Lhs>::type
814template <
typename Rhs>
815inline const typename internal::result_type<Rhs>::type
818template <
typename Lhs>
819inline const typename internal::result_type<Lhs>::type
823template <
typename Rhs>
824inline const typename internal::result_type<Rhs>::type
827template <
typename Lhs>
828inline const typename internal::result_type<Lhs>::type
832template <
typename Rhs>
833inline const typename internal::result_type<Rhs>::type
836template <
typename Lhs>
837inline const typename internal::result_type<Lhs>::type
842const mpreal sqrt(
const unsigned int v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
843const mpreal sqrt(
const long int v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
844const mpreal sqrt(
const int v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
845const mpreal sqrt(
const long double v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
846const mpreal sqrt(
const double v, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
849inline const mpreal
abs(
const mpreal&
x, mp_rnd_t r = mpreal::get_default_rnd());
853const mpreal pow(
const mpreal& a,
const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
854const mpreal pow(
const mpreal& a,
const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
855const mpreal pow(
const mpreal& a,
const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
856const mpreal pow(
const mpreal& a,
const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
858const mpreal pow(
const unsigned int a,
const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
859const mpreal pow(
const long int a,
const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
860const mpreal pow(
const int a,
const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
861const mpreal pow(
const long double a,
const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
862const mpreal pow(
const double a,
const mpreal& b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
864const mpreal pow(
const unsigned long int a,
const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
865const mpreal pow(
const unsigned long int a,
const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
866const mpreal pow(
const unsigned long int a,
const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
867const mpreal pow(
const unsigned long int a,
const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
868const mpreal pow(
const unsigned long int a,
const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
870const mpreal pow(
const unsigned int a,
const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
871const mpreal pow(
const unsigned int a,
const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
872const mpreal pow(
const unsigned int a,
const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
873const mpreal pow(
const unsigned int a,
const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
874const mpreal pow(
const unsigned int a,
const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
875const mpreal pow(
const unsigned int a,
const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
877const mpreal pow(
const long int a,
const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
878const mpreal pow(
const long int a,
const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
879const mpreal pow(
const long int a,
const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
880const mpreal pow(
const long int a,
const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
881const mpreal pow(
const long int a,
const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
882const mpreal pow(
const long int a,
const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
884const mpreal pow(
const int a,
const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
885const mpreal pow(
const int a,
const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
886const mpreal pow(
const int a,
const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
887const mpreal pow(
const int a,
const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
888const mpreal pow(
const int a,
const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
889const mpreal pow(
const int a,
const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
891const mpreal pow(
const long double a,
const long double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
892const mpreal pow(
const long double a,
const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
893const mpreal pow(
const long double a,
const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
894const mpreal pow(
const long double a,
const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
895const mpreal pow(
const long double a,
const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
897const mpreal pow(
const double a,
const double b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
898const mpreal pow(
const double a,
const unsigned long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
899const mpreal pow(
const double a,
const unsigned int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
900const mpreal pow(
const double a,
const long int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
901const mpreal pow(
const double a,
const int b, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
903inline const mpreal mul_2ui(
const mpreal& v,
unsigned long int k, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
904inline const mpreal mul_2si(
const mpreal& v,
long int k, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
905inline const mpreal div_2ui(
const mpreal& v,
unsigned long int k, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
906inline const mpreal div_2si(
const mpreal& v,
long int k, mp_rnd_t rnd_mode = mpreal::get_default_rnd());
911inline mpreal machine_epsilon(mp_prec_t prec = mpreal::get_default_prec());
914inline mpreal machine_epsilon(
const mpreal&
x);
919inline mpreal minval(mp_prec_t prec = mpreal::get_default_prec());
920inline mpreal maxval(mp_prec_t prec = mpreal::get_default_prec());
923inline bool isEqualFuzzy(
const mpreal& a,
const mpreal& b,
const mpreal& eps);
926inline bool isEqualFuzzy(
const mpreal& a,
const mpreal& b);
930inline bool isEqualUlps(
const mpreal& a,
const mpreal& b,
int maxUlps);
937inline mp_prec_t digits2bits(
int d);
938inline int bits2digits(mp_prec_t b);
942const mpreal (
max)(
const mpreal&
x,
const mpreal& y);
943const mpreal (min)(
const mpreal&
x,
const mpreal& y);
1004#if (MPREAL_DOUBLE_BITS_OVERFLOW > -1)
1112template <
typename real_t>
1113inline mpreal& mpreal::operator= (
const std::complex<real_t>& z)
1115 return *
this = z.real();
1148inline mpreal& mpreal::operator+= (
const long double u)
1155inline mpreal& mpreal::operator+= (
const double u)
1157#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
1269#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
1323#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
1394#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
1470#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
1544#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
1620 return mul_2ui(v,
static_cast<unsigned long int>(k));
1630 return mul_2si(v,
static_cast<long int>(k));
1645 return div_2ui(v,
static_cast<unsigned long int>(k));
1650 return div_2si(v,
static_cast<long int>(k));
1697inline bool operator > (
const mpreal& a,
const unsigned long int b ){
return !
isnan(a) && (mpfr_cmp_ui(a.
mpfr_srcptr(),b) > 0 ); }
1701inline bool operator > (
const mpreal& a,
const long double b ){
return !
isnan(a) && (b == b) && (mpfr_cmp_ld(a.
mpfr_srcptr(),b) > 0 ); }
1702inline bool operator > (
const mpreal& a,
const double b ){
return !
isnan(a) && (b == b) && (mpfr_cmp_d (a.
mpfr_srcptr(),b) > 0 ); }
1705inline bool operator >= (
const mpreal& a,
const unsigned long int b ){
return !
isnan(a) && (mpfr_cmp_ui(a.
mpfr_srcptr(),b) >= 0 ); }
1706inline bool operator >= (
const mpreal& a,
const unsigned int b ){
return !
isnan(a) && (mpfr_cmp_ui(a.
mpfr_srcptr(),b) >= 0 ); }
1709inline bool operator >= (
const mpreal& a,
const long double b ){
return !
isnan(a) && (b == b) && (mpfr_cmp_ld(a.
mpfr_srcptr(),b) >= 0 ); }
1710inline bool operator >= (
const mpreal& a,
const double b ){
return !
isnan(a) && (b == b) && (mpfr_cmp_d (a.
mpfr_srcptr(),b) >= 0 ); }
1713inline bool operator < (
const mpreal& a,
const unsigned long int b ){
return !
isnan(a) && (mpfr_cmp_ui(a.
mpfr_srcptr(),b) < 0 ); }
1717inline bool operator < (
const mpreal& a,
const long double b ){
return !
isnan(a) && (b == b) && (mpfr_cmp_ld(a.
mpfr_srcptr(),b) < 0 ); }
1718inline bool operator < (
const mpreal& a,
const double b ){
return !
isnan(a) && (b == b) && (mpfr_cmp_d (a.
mpfr_srcptr(),b) < 0 ); }
1721inline bool operator <= (
const mpreal& a,
const unsigned long int b ){
return !
isnan(a) && (mpfr_cmp_ui(a.
mpfr_srcptr(),b) <= 0 ); }
1722inline bool operator <= (
const mpreal& a,
const unsigned int b ){
return !
isnan(a) && (mpfr_cmp_ui(a.
mpfr_srcptr(),b) <= 0 ); }
1725inline bool operator <= (
const mpreal& a,
const long double b ){
return !
isnan(a) && (b == b) && (mpfr_cmp_ld(a.
mpfr_srcptr(),b) <= 0 ); }
1726inline bool operator <= (
const mpreal& a,
const double b ){
return !
isnan(a) && (b == b) && (mpfr_cmp_d (a.
mpfr_srcptr(),b) <= 0 ); }
1750#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
1770inline std::string
toString(
T t, std::ios_base & (*f)(std::ios_base&))
1772 std::ostringstream oss;
1777#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
1784 if( !format.empty() )
1786 if(!(mpfr_asprintf(&
s, format.c_str(),
mpfr_srcptr()) < 0))
1788 out = std::string(
s);
1805#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
1807 std::ostringstream format;
1811 format <<
"%." << digits <<
"RNg";
1817 char *
s, *ns = NULL;
1824 if(mpfr_sgn(
mp)>0)
return "+Inf";
1828 if(mpfr_zero_p(
mp))
return "0";
1829 if(mpfr_nan_p(
mp))
return "NaN";
1831 s = mpfr_get_str(NULL, &
exp, b, 0,
mp, mode);
1832 ns = mpfr_get_str(NULL, &
exp, b, (std::max)(0,n),
mp, mode);
1834 if(
s!=NULL && ns!=NULL)
1849 if (
exp>0 &&
static_cast<size_t>(
exp)<slen)
1854 char* ptr =
s+slen-1;
1855 while (*ptr==
'0' && ptr>
s+
exp) ptr--;
1857 if(ptr==
s+
exp) out = std::string(
s,
exp+1);
1858 else out = std::string(
s,
exp+1)+
'.'+std::string(
s+
exp+1,ptr-(
s+
exp+1)+1);
1865 char* ptr =
s+slen-1;
1866 while (*ptr==
'0' && ptr>
s+
exp-1) ptr--;
1868 if(ptr==
s+
exp-1) out = std::string(
s,
exp);
1869 else out = std::string(
s,
exp)+
'.'+std::string(
s+
exp,ptr-(
s+
exp)+1);
1878 char* ptr =
s+slen-1;
1879 while (*ptr==
'0' && ptr>
s+1) ptr--;
1881 if(ptr==
s+1) out = std::string(
s,2);
1882 else out = std::string(
s,2)+
'.'+std::string(
s+2,ptr-(
s+2)+1);
1889 char* ptr =
s+slen-1;
1890 while (*ptr==
'0' && ptr>
s) ptr--;
1892 if(ptr==
s) out = std::string(
s,1);
1893 else out = std::string(
s,1)+
'.'+std::string(
s+1,ptr-(
s+1)+1);
1901 if(
exp>0) out +=
"e+"+mpfr::toString<mp_exp_t>(
exp,std::dec);
1902 else out +=
"e"+mpfr::toString<mp_exp_t>(
exp,std::dec);
1909 return "conversion error!";
1919 std::ostringstream format;
1920 const std::ios::fmtflags flags = os.flags();
1922 format << ((flags & std::ios::showpos) ?
"%+" :
"%");
1923 if (os.precision() >= 0)
1924 format <<
'.' << os.precision() <<
"R*"
1925 << ((flags & std::ios::floatfield) == std::ios::fixed ?
'f' :
1926 (flags & std::ios::floatfield) == std::ios::scientific ?
'e' :
1932 if(!(mpfr_asprintf(&
s, format.str().c_str(),
1937 os << std::string(
s);
1964 const double LOG2_10 = 3.3219280948873624;
1966 return mp_prec_t(std::ceil( d * LOG2_10 ));
1971 const double LOG10_2 = 0.30102999566398119;
1973 return int(std::floor( b * LOG10_2 ));
1992 mpfr_prec_round(
mpfr_ptr(), Precision, RoundingMode);
2013#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
2016 mpfr_set_si(
mpfr_ptr(), 0, (mpfr_get_default_rounding_mode)());
2031 mpfr_prec_round(
mpfr_ptr(),prec,rnd_mode);
2056#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,1,0))
2125 return abs(a - b) <= eps;
2137 mpreal rop(0, mpfr_get_prec(
x.mpfr_ptr()));
2144 return mpfr_signbit(
x.mpfr_srcptr());
2149 mpfr_setsign(
x.mpfr_ptr(),
x.mpfr_srcptr(), minus, rnd_mode);
2165 return mpfr_check_range(
mpfr_ptr(),t,rnd_mode);
2170 int r = mpfr_subnormalize(
mpfr_ptr(),t,rnd_mode);
2177 return mpfr_get_emin();
2182 return mpfr_set_emin(
exp);
2187 return mpfr_get_emax();
2192 return mpfr_set_emax(
exp);
2197 return mpfr_get_emin_min();
2202 return mpfr_get_emin_max();
2207 return mpfr_get_emax_min();
2212 return mpfr_get_emax_max();
2220#define MPREAL_UNARY_MATH_FUNCTION_BODY(f) \
2221 mpreal y(0, mpfr_get_prec(x.mpfr_srcptr())); \
2222 mpfr_##f(y.mpfr_ptr(), x.mpfr_srcptr(), r); \
2226#define MPREAL_BINARY_MATH_FUNCTION_UI_BODY(f, u) \
2227 mpreal y(0, mpfr_get_prec(x.mpfr_srcptr())); \
2228 mpfr_##f(y.mpfr_ptr(), x.mpfr_srcptr(), u, r); \
2246 return sqrt(
static_cast<unsigned long int>(v),rnd_mode);
2251 if (v>=0)
return sqrt(
static_cast<unsigned long int>(v),rnd_mode);
2257 if (v>=0)
return sqrt(
static_cast<unsigned long int>(v),rnd_mode);
2263 mpreal y(0, mpfr_get_prec(
x.mpfr_srcptr()));
2264#if (MPFR_VERSION >= MPFR_VERSION_NUM(4,0,0))
2265 mpfr_rootn_ui(y.
mpfr_ptr(),
x.mpfr_srcptr(), k, r);
2267 mpfr_root(y.
mpfr_ptr(),
x.mpfr_srcptr(), k, r);
2345#if (MPFR_VERSION >= MPFR_VERSION_NUM(4,0,0))
2372 mpfr_log_ui(y.
mpfr_ptr(),n,rnd_mode);
2377#if (MPFR_VERSION >= MPFR_VERSION_NUM(4,2,0))
2430 mpreal y(0,
x.getPrecision());
2431 mpfr_compound_si(y.
mpfr_ptr(),
x.mpfr_srcptr(),n,rnd_mode);
2444 mpreal y(0,
x.getPrecision());
2472 mpreal w = (std::max)(absa, (std::max)(absb, absc));
2491 mpreal w = (std::max)(absa, (std::max)(absb, (std::max)(absc, absd)));
2516 if (q) *q =
int(lq);
2524 mpfr_fac_ui(
x.mpfr_ptr(),v,rnd_mode);
2534 if(signp) mpfr_lgamma(
x.mpfr_ptr(), signp,v.
mpfr_srcptr(),rnd_mode);
2535 else mpfr_lgamma(
x.mpfr_ptr(),&tsignp,v.
mpfr_srcptr(),rnd_mode);
2543 mpreal y(0,
x.getPrecision());
2544 mpfr_jn(y.
mpfr_ptr(), n,
x.mpfr_srcptr(), r);
2550 mpreal y(0,
x.getPrecision());
2551 mpfr_yn(y.
mpfr_ptr(), n,
x.mpfr_srcptr(), r);
2558 mp_prec_t
p1, p2, p3;
2566 mpfr_fma(a.
mp,v1.
mp,v2.
mp,v3.
mp,rnd_mode);
2573 mp_prec_t
p1, p2, p3;
2581 mpfr_fms(a.
mp,v1.
mp,v2.
mp,v3.
mp,rnd_mode);
2595 mpfr_agm(a.
mp, v1.
mp, v2.
mp, rnd_mode);
2604 for (
unsigned long int i = 0; i < n; i++)
2608 status = mpfr_sum(
x.mpfr_ptr(), (
mpfr_ptr*)
p, n, mode);
2616#if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
2620 return mpfr_sinh_cosh(
s.mp,c.
mp,v.
mp,rnd_mode);
2631 return fmod(
x, y, rnd_mode);
2650 if(
x == y)
return 0;
2667 mpfr_fmod(a.
mp,
x.mp, y.
mp, rnd_mode);
2675 mpfr_rec_sqrt(
x.mp,v.
mp,rnd_mode);
2682#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
2692 mpfr_const_log2(
x.mpfr_ptr(), r);
2699 mpfr_const_pi(
x.mpfr_ptr(), r);
2706 mpfr_const_euler(
x.mpfr_ptr(), r);
2713 mpfr_const_catalan(
x.mpfr_ptr(), r);
2720 mpfr_set_inf(
x.mpfr_ptr(), sign);
2729 mpfr_ceil(
x.mp,v.
mp);
2736 mpfr_floor(
x.mp,v.
mp);
2743 mpfr_round(
x.mp,v.
mp);
2749 long r = std::numeric_limits<long>::min();
2758 long long r = std::numeric_limits<long long>::min();
2768 mpfr_trunc(
x.mp,v.
mp);
2797 mpfr_max(a.
mp,
x.mp,y.
mp,rnd_mode);
2804 mpfr_min(a.
mp,
x.mp,y.
mp,rnd_mode);
2811 mpfr_nexttoward(a.
mp,y.
mp);
2818 mpfr_nextabove(a.
mp);
2825 mpfr_nextbelow(a.
mp);
2832 mpfr_urandomb(
x.mpfr_ptr(),
state);
2836#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
2840 mpfr_urandom(
x.mpfr_ptr(),
state, rnd_mode);
2845#if (MPFR_VERSION <= MPFR_VERSION_NUM(2,4,2))
2849 mpfr_random2(
x.mpfr_ptr(),size,
exp);
2860#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
2861 static gmp_randstate_t
state;
2862 static bool initialize =
true;
2866 gmp_randinit_default(
state);
2867 gmp_randseed_ui(
state,0);
2871 if(seed != 0) gmp_randseed_ui(
state,seed);
2875 if(seed != 0) std::srand(seed);
2876 return mpfr::mpreal(std::rand()/(
double)RAND_MAX);
2880#if (MPFR_VERSION >= MPFR_VERSION_NUM(3,1,0))
2884#if (MPFR_VERSION >= MPFR_VERSION_NUM(4,0,0))
2885 mpfr_nrandom(
x.mpfr_ptr(),
state, rnd_mode);
2887 mpfr_grandom(
x.mpfr_ptr(), NULL,
state, rnd_mode);
2894 static gmp_randstate_t
state;
2895 static bool initialize =
true;
2899 gmp_randinit_default(
state);
2900 gmp_randseed_ui(
state,0);
2904 if(seed != 0) gmp_randseed_ui(
state,seed);
2914 mpfr_set_default_prec(prec);
2919 mpfr_set_default_rounding_mode(rnd_mode);
2926 return IsInf(
x) || (std::modf ( std::ldexp ( std::frexp (
x, &i ), n ), &t ) == 0.0);
2932 mpfr_pow(
x.mp,
x.mp,b.
mp,rnd_mode);
2939 mpfr_pow_z(
x.mp,
x.mp,b,rnd_mode);
2958 mpfr_pow_ui(
x.mp,
x.mp,b,rnd_mode);
2964 return pow(a,
static_cast<unsigned long int>(b),rnd_mode);
2970 mpfr_pow_si(
x.mp,
x.mp,b,rnd_mode);
2976 return pow(a,
static_cast<long int>(b),rnd_mode);
2992 mpfr_ui_pow(
x.mp,a,b.
mp,rnd_mode);
2998 return pow(
static_cast<unsigned long int>(a),b,rnd_mode);
3003 if (a>=0)
return pow(
static_cast<unsigned long int>(a),b,rnd_mode);
3009 if (a>=0)
return pow(
static_cast<unsigned long int>(a),b,rnd_mode);
3024inline const mpreal pow(
const unsigned long int a,
const unsigned long int b, mp_rnd_t rnd_mode)
3027 mpfr_ui_pow_ui(
x.mp,a,b,rnd_mode);
3031inline const mpreal pow(
const unsigned long int a,
const unsigned int b, mp_rnd_t rnd_mode)
3033 return pow(a,
static_cast<unsigned long int>(b),rnd_mode);
3036inline const mpreal pow(
const unsigned long int a,
const long int b, mp_rnd_t rnd_mode)
3038 if(b>0)
return pow(a,
static_cast<unsigned long int>(b),rnd_mode);
3042inline const mpreal pow(
const unsigned long int a,
const int b, mp_rnd_t rnd_mode)
3044 if(b>0)
return pow(a,
static_cast<unsigned long int>(b),rnd_mode);
3048inline const mpreal pow(
const unsigned long int a,
const long double b, mp_rnd_t rnd_mode)
3053inline const mpreal pow(
const unsigned long int a,
const double b, mp_rnd_t rnd_mode)
3059inline const mpreal pow(
const unsigned int a,
const unsigned long int b, mp_rnd_t rnd_mode)
3061 return pow(
static_cast<unsigned long int>(a),b,rnd_mode);
3064inline const mpreal pow(
const unsigned int a,
const unsigned int b, mp_rnd_t rnd_mode)
3066 return pow(
static_cast<unsigned long int>(a),
static_cast<unsigned long int>(b),rnd_mode);
3069inline const mpreal pow(
const unsigned int a,
const long int b, mp_rnd_t rnd_mode)
3071 if(b>0)
return pow(
static_cast<unsigned long int>(a),
static_cast<unsigned long int>(b),rnd_mode);
3072 else return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3075inline const mpreal pow(
const unsigned int a,
const int b, mp_rnd_t rnd_mode)
3077 if(b>0)
return pow(
static_cast<unsigned long int>(a),
static_cast<unsigned long int>(b),rnd_mode);
3078 else return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3081inline const mpreal pow(
const unsigned int a,
const long double b, mp_rnd_t rnd_mode)
3083 return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3086inline const mpreal pow(
const unsigned int a,
const double b, mp_rnd_t rnd_mode)
3088 return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3092inline const mpreal pow(
const long int a,
const unsigned long int b, mp_rnd_t rnd_mode)
3094 if (a>0)
return pow(
static_cast<unsigned long int>(a),b,rnd_mode);
3098inline const mpreal pow(
const long int a,
const unsigned int b, mp_rnd_t rnd_mode)
3100 if (a>0)
return pow(
static_cast<unsigned long int>(a),
static_cast<unsigned long int>(b),rnd_mode);
3101 else return pow(
mpreal(a),
static_cast<unsigned long int>(b),rnd_mode);
3104inline const mpreal pow(
const long int a,
const long int b, mp_rnd_t rnd_mode)
3108 if(b>0)
return pow(
static_cast<unsigned long int>(a),
static_cast<unsigned long int>(b),rnd_mode);
3109 else return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3115inline const mpreal pow(
const long int a,
const int b, mp_rnd_t rnd_mode)
3119 if(b>0)
return pow(
static_cast<unsigned long int>(a),
static_cast<unsigned long int>(b),rnd_mode);
3120 else return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3122 return pow(
mpreal(a),
static_cast<long int>(b),rnd_mode);
3126inline const mpreal pow(
const long int a,
const long double b, mp_rnd_t rnd_mode)
3128 if (a>=0)
return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3132inline const mpreal pow(
const long int a,
const double b, mp_rnd_t rnd_mode)
3134 if (a>=0)
return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3139inline const mpreal pow(
const int a,
const unsigned long int b, mp_rnd_t rnd_mode)
3141 if (a>0)
return pow(
static_cast<unsigned long int>(a),b,rnd_mode);
3145inline const mpreal pow(
const int a,
const unsigned int b, mp_rnd_t rnd_mode)
3147 if (a>0)
return pow(
static_cast<unsigned long int>(a),
static_cast<unsigned long int>(b),rnd_mode);
3148 else return pow(
mpreal(a),
static_cast<unsigned long int>(b),rnd_mode);
3151inline const mpreal pow(
const int a,
const long int b, mp_rnd_t rnd_mode)
3155 if(b>0)
return pow(
static_cast<unsigned long int>(a),
static_cast<unsigned long int>(b),rnd_mode);
3156 else return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3162inline const mpreal pow(
const int a,
const int b, mp_rnd_t rnd_mode)
3166 if(b>0)
return pow(
static_cast<unsigned long int>(a),
static_cast<unsigned long int>(b),rnd_mode);
3167 else return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3169 return pow(
mpreal(a),
static_cast<long int>(b),rnd_mode);
3173inline const mpreal pow(
const int a,
const long double b, mp_rnd_t rnd_mode)
3175 if (a>=0)
return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3179inline const mpreal pow(
const int a,
const double b, mp_rnd_t rnd_mode)
3181 if (a>=0)
return pow(
static_cast<unsigned long int>(a),
mpreal(b),rnd_mode);
3186inline const mpreal pow(
const long double a,
const long double b, mp_rnd_t rnd_mode)
3191inline const mpreal pow(
const long double a,
const unsigned long int b, mp_rnd_t rnd_mode)
3196inline const mpreal pow(
const long double a,
const unsigned int b, mp_rnd_t rnd_mode)
3198 return pow(
mpreal(a),
static_cast<unsigned long int>(b),rnd_mode);
3201inline const mpreal pow(
const long double a,
const long int b, mp_rnd_t rnd_mode)
3206inline const mpreal pow(
const long double a,
const int b, mp_rnd_t rnd_mode)
3208 return pow(
mpreal(a),
static_cast<long int>(b),rnd_mode);
3211inline const mpreal pow(
const double a,
const double b, mp_rnd_t rnd_mode)
3216inline const mpreal pow(
const double a,
const unsigned long int b, mp_rnd_t rnd_mode)
3221inline const mpreal pow(
const double a,
const unsigned int b, mp_rnd_t rnd_mode)
3223 return pow(
mpreal(a),
static_cast<unsigned long int>(b),rnd_mode);
3226inline const mpreal pow(
const double a,
const long int b, mp_rnd_t rnd_mode)
3231inline const mpreal pow(
const double a,
const int b, mp_rnd_t rnd_mode)
3233 return pow(
mpreal(a),
static_cast<long int>(b),rnd_mode);
3244 inline void swap(mpfr::mpreal&
x, mpfr::mpreal& y)
3246 return mpfr::swap(
x, y);
3271 inline static mpfr::mpreal (
min) (mp_prec_t precision = mpfr::mpreal::get_default_prec()) {
return mpfr::minval(precision); }
3272 inline static mpfr::mpreal (
max) (mp_prec_t precision = mpfr::mpreal::get_default_prec()) {
return mpfr::maxval(precision); }
3273 inline static mpfr::mpreal
lowest (mp_prec_t precision = mpfr::mpreal::get_default_prec()) {
return -mpfr::maxval(precision); }
3276 inline static mpfr::mpreal
epsilon(mp_prec_t precision = mpfr::mpreal::get_default_prec()) {
return mpfr::machine_epsilon(precision); }
3279 inline static mpfr::mpreal
epsilon(
const mpfr::mpreal&
x) {
return mpfr::machine_epsilon(
x); }
3281 inline static mpfr::mpreal
round_error(mp_prec_t precision = mpfr::mpreal::get_default_prec())
3283 mp_rnd_t r = mpfr::mpreal::get_default_rnd();
3285 if(r == GMP_RNDN)
return mpfr::mpreal(0.5, precision);
3286 else return mpfr::mpreal(1.0, precision);
3289 inline static const mpfr::mpreal
infinity() {
return mpfr::const_infinity(); }
3300#ifdef MPREAL_HAVE_DYNAMIC_STD_NUMERIC_LIMITS
3310 mp_rnd_t r = mpfr::mpreal::get_default_rnd();
3314 case GMP_RNDN:
return round_to_nearest;
3315 case GMP_RNDZ:
return round_toward_zero;
3316 case GMP_RNDU:
return round_toward_infinity;
3317 case GMP_RNDD:
return round_toward_neg_infinity;
3318 default:
return round_indeterminate;
3322 inline static int digits() {
return int(mpfr::mpreal::get_default_prec()); }
3323 inline static int digits(
const mpfr::mpreal&
x) {
return x.getPrecision(); }
3325 inline static int digits10(mp_prec_t precision = mpfr::mpreal::get_default_prec())
3327 return mpfr::bits2digits(precision);
3332 return mpfr::bits2digits(
x.getPrecision());
3335 inline static int max_digits10(mp_prec_t precision = mpfr::mpreal::get_default_prec())
3353 static const std::float_round_style round_style = round_to_nearest;
3354 static const int digits = 53;
3355 static const int digits10 = 15;
3356 static const int max_digits10 = 16;
friend const mpreal rec_sqrt(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal acot(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t rnd_mode)
static mp_exp_t get_emax_min(void)
friend const mpreal log1p(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal acsc(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal root(const mpreal &v, unsigned long int k, mp_rnd_t rnd_mode)
friend const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t rnd_mode)
friend const mpreal remquo(const mpreal &x, const mpreal &y, int *q, mp_rnd_t rnd_mode)
friend const mpreal log2(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal fmax(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode)
friend const mpreal sqr(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal acos(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal rint_trunc(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal nextbelow(const mpreal &x)
friend const mpreal acosh(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal nextpow2(const mpreal &v, mp_rnd_t rnd_mode)
mpreal & operator=(const mpreal &v)
friend const mpreal sec(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal li2(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal cos(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal mul_2ui(const mpreal &v, unsigned long int k, mp_rnd_t rnd_mode)
friend const mpreal div_2si(const mpreal &v, long int k, mp_rnd_t rnd_mode)
friend const mpreal agm(const mpreal &v1, const mpreal &v2, mp_rnd_t rnd_mode)
friend const mpreal zeta(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal rem(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode)
friend const mpreal sin(const mpreal &v, mp_rnd_t rnd_mode)
friend bool isfinite(const mpreal &v)
const mpreal operator-() const
unsigned long toULong(mp_rnd_t mode=GMP_RNDZ) const
friend const mpreal const_catalan(mp_prec_t prec, mp_rnd_t rnd_mode)
friend const mpreal fmin(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode)
static void set_default_rnd(mp_rnd_t rnd_mode)
friend const mpreal coth(const mpreal &v, mp_rnd_t rnd_mode)
friend int sinh_cosh(mpreal &s, mpreal &c, const mpreal &v, mp_rnd_t rnd_mode)
static mp_exp_t get_emin(void)
friend const mpreal fac_ui(unsigned long int v, mp_prec_t prec, mp_rnd_t rnd_mode)
friend const mpreal const_pi(mp_prec_t prec, mp_rnd_t rnd_mode)
friend const mpreal abs(const mpreal &v, mp_rnd_t rnd_mode)
double toDouble(mp_rnd_t mode=GMP_RNDN) const
std::ostream & output(std::ostream &os) const
MPREAL_MSVC_DEBUGVIEW_DATA void clear(::mpfr_ptr)
friend const mpreal round(const mpreal &v)
friend const mpreal exp2(const mpreal &v, mp_rnd_t rnd_mode)
mp_prec_t get_prec() const
int subnormalize(int t, mp_rnd_t rnd_mode=get_default_rnd())
const mpreal operator+() const
friend const mpreal remainder(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode)
mpreal & setSign(int Sign, mp_rnd_t RoundingMode=get_default_rnd())
friend int sin_cos(mpreal &s, mpreal &c, const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal atan(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal besselj0(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal operator/(const unsigned long int b, const mpreal &a)
friend const mpreal acoth(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal csc(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal logb(const mpreal &v, mp_rnd_t rnd_mode)
mpreal & setInf(int Sign=+1)
long double toLDouble(mp_rnd_t mode=GMP_RNDN) const
friend const mpreal sqrt(const mpreal &v, mp_rnd_t rnd_mode)
long toLong(mp_rnd_t mode=GMP_RNDZ) const
static int set_emin(mp_exp_t exp)
friend const mpreal lgamma(const mpreal &v, int *signp, mp_rnd_t rnd_mode)
friend const mpreal eint(const mpreal &v, mp_rnd_t rnd_mode)
::mpfr_srcptr mpfr_srcptr() const
mpreal & operator+=(const mpreal &v)
friend const mpreal cot(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal asin(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal pow(const mpreal &a, const mpreal &b, mp_rnd_t rnd_mode)
friend const mpreal urandomb(gmp_randstate_t &state)
friend const mpreal frac(const mpreal &v, mp_rnd_t rnd_mode)
mpreal & operator*=(const long long int u)
friend const mpreal floor(const mpreal &v)
friend const mpreal rint_floor(const mpreal &v, mp_rnd_t rnd_mode)
float toFloat(mp_rnd_t mode=GMP_RNDN) const
static mp_exp_t get_emax(void)
static mp_exp_t get_emax_max(void)
friend const mpreal mod(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode)
friend long lround(const mpreal &v)
mpreal & setZero(int Sign=+1)
friend const mpreal exp10(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal erf(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal log(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal rint_round(const mpreal &v, mp_rnd_t rnd_mode)
friend int sgn(const mpreal &v)
friend const mpreal acsch(const mpreal &v, mp_rnd_t rnd_mode)
friend std::istream & operator>>(std::istream &is, mpreal &v)
mpreal & operator>>=(const unsigned long int u)
friend const mpreal fmod(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode)
friend const mpreal ceil(const mpreal &v)
friend const mpreal nextabove(const mpreal &x)
friend const mpreal csch(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal rint_ceil(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal fms(const mpreal &v1, const mpreal &v2, const mpreal &v3, mp_rnd_t rnd_mode)
friend const mpreal random(unsigned int seed)
void set_prec(mp_prec_t prec, mp_rnd_t rnd_mode=get_default_rnd())
friend const mpreal urandom(gmp_randstate_t &state, mp_rnd_t rnd_mode)
friend const mpreal const_euler(mp_prec_t prec, mp_rnd_t rnd_mode)
friend const mpreal asec(const mpreal &v, mp_rnd_t rnd_mode)
friend bool isinf(const mpreal &v)
mpreal & operator-=(const long long int u)
friend const mpreal cosh(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal gamma(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal grandom(gmp_randstate_t &state, mp_rnd_t rnd_mode)
friend const mpreal fabs(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal rint(const mpreal &v, mp_rnd_t rnd_mode)
static int set_emax(mp_exp_t exp)
friend const mpreal const_infinity(int sign, mp_prec_t prec)
friend const mpreal besselyn(long n, const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal erfc(const mpreal &v, mp_rnd_t rnd_mode)
static void set_default_prec(mp_prec_t prec)
friend const mpreal const_log2(mp_prec_t prec, mp_rnd_t rnd_mode)
mpreal & operator/=(const long long int u)
friend const mpreal besselj1(const mpreal &v, mp_rnd_t rnd_mode)
int check_range(int t, mp_rnd_t rnd_mode=get_default_rnd())
long long toLLong(mp_rnd_t mode=GMP_RNDZ) const
friend bool isint(const mpreal &v)
friend bool isregular(const mpreal &v)
static mp_exp_t get_emin_min(void)
friend const mpreal ai(const mpreal &v, mp_rnd_t rnd_mode)
static mp_prec_t get_default_prec()
friend const mpreal trunc(const mpreal &v)
friend const mpreal modf(const mpreal &v, mpreal &n)
friend bool isnan(const mpreal &v)
friend int cmpabs(const mpreal &a, const mpreal &b)
friend const mpreal bessely1(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal fma(const mpreal &v1, const mpreal &v2, const mpreal &v3, mp_rnd_t rnd_mode)
unsigned long long toULLong(mp_rnd_t mode=GMP_RNDZ) const
friend bool iszero(const mpreal &v)
mpreal & operator<<=(const unsigned long int u)
friend const mpreal asinh(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal cbrt(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal lngamma(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal digamma(const mpreal &v, mp_rnd_t rnd_mode)
static mp_exp_t get_emin_max(void)
static mp_rnd_t get_default_rnd()
friend const mpreal atan2(const mpreal &y, const mpreal &x, mp_rnd_t rnd_mode)
friend const mpreal hypot(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode)
std::string toString(int n=-1, int b=10, mp_rnd_t mode=mpreal::get_default_rnd()) const
friend const mpreal besseljn(long n, const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal sech(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal div_2ui(const mpreal &v, unsigned long int k, mp_rnd_t rnd_mode)
friend const mpreal bessely0(const mpreal &v, mp_rnd_t rnd_mode)
friend bool isnum(const mpreal &v)
friend const mpreal atanh(const mpreal &v, mp_rnd_t rnd_mode)
friend mp_exp_t ilogb(const mpreal &v)
mpreal & setPrecision(int Precision, mp_rnd_t RoundingMode=get_default_rnd())
friend const mpreal mul_2si(const mpreal &v, long int k, mp_rnd_t rnd_mode)
friend const mpreal expm1(const mpreal &v, mp_rnd_t rnd_mode)
bool fits_in_bits(double x, int n)
friend const mpreal tgamma(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal random2(mp_size_t size, mp_exp_t exp)
friend const mpreal exp(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal asech(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal tan(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal nexttoward(const mpreal &x, const mpreal &y)
friend long long llround(const mpreal &v)
friend const mpreal sinh(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal tanh(const mpreal &v, mp_rnd_t rnd_mode)
friend const mpreal log10(const mpreal &v, mp_rnd_t rnd_mode)
static const mpfr::mpreal signaling_NaN()
static const bool tinyness_before
static const bool is_signed
static const bool has_quiet_NaN
static int digits10(mp_prec_t precision=mpfr::mpreal::get_default_prec())
static const mpfr::mpreal quiet_NaN()
static const bool is_bounded
static const bool has_signaling_NaN
static const float_denorm_style has_denorm
static mpfr::mpreal max(mp_prec_t precision=mpfr::mpreal::get_default_prec())
static int max_digits10(mp_prec_t precision=mpfr::mpreal::get_default_prec())
static const bool has_infinity
static mpfr::mpreal round_error(mp_prec_t precision=mpfr::mpreal::get_default_prec())
static const mpfr::mpreal denorm_min()
static const bool is_iec559
static const bool is_specialized
static mpfr::mpreal epsilon(mp_prec_t precision=mpfr::mpreal::get_default_prec())
static const bool is_modulo
static MPREAL_PERMISSIVE_EXPR const int min_exponent10
static const mpfr::mpreal infinity()
static const int min_exponent
static const bool is_integer
static int digits(const mpfr::mpreal &x)
static const bool is_exact
static MPREAL_PERMISSIVE_EXPR const int max_exponent10
static int digits10(const mpfr::mpreal &x)
static float_round_style round_style()
static const int max_exponent
static mpfr::mpreal min(mp_prec_t precision=mpfr::mpreal::get_default_prec())
static mpfr::mpreal epsilon(const mpfr::mpreal &x)
static mpfr::mpreal lowest(mp_prec_t precision=mpfr::mpreal::get_default_prec())
static CanonicalForm base
std::ostream & operator<<(std::ostream &o, const std::pair< T1, T2 > &p)
std::ostringstream & toString(std::ostringstream &o, int len, int *p)
#define MPREAL_UNARY_MATH_FUNCTION_BODY(f)
#define MPREAL_PERMISSIVE_EXPR
#define mpfr_set_zero_fast(x)
#define MPREAL_BINARY_MATH_FUNCTION_UI_BODY(f, u)
#define MPREAL_MSVC_DEBUGVIEW_DATA
#define MPREAL_MSVC_DEBUGVIEW_CODE
#define MPREAL_DOUBLE_BITS_OVERFLOW
bool operator!=(const StatsAllocator< T1 > &, const StatsAllocator< T2 > &) noexcept
bool operator==(const StatsAllocator< T1 > &, const StatsAllocator< T2 > &) noexcept
const mpreal ldexp(const mpreal &v, mp_exp_t exp)
const mpreal sqrt(const unsigned int v, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal div_2ui(const mpreal &v, unsigned long int k, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal grandom(gmp_randstate_t &state, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal asinu(const mpreal &x, unsigned long u, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal min(const mpreal &x, const mpreal &y)
const mpreal cosu(const mpreal &x, unsigned long u, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal sinpi(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
bool signbit(const mpreal &x)
int bits2digits(mp_prec_t b)
const mpreal urandom(gmp_randstate_t &state, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const internal::result_type< Rhs >::type operator+(const mpreal &lhs, const Rhs &rhs)
const mpreal cospi(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal mul_2ui(const mpreal &v, unsigned long int k, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal acosu(const mpreal &x, unsigned long u, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal hypot(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal scalbn(const mpreal &v, mp_exp_t exp)
const internal::result_type< Rhs >::type operator-(const mpreal &lhs, const Rhs &rhs)
bool isnan(const mpreal &op)
mpreal copysign(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
mpreal minval(mp_prec_t prec=mpreal::get_default_prec())
const mpreal gammainc(const mpreal &a, const mpreal &x, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const internal::result_type< Rhs >::type operator*(const mpreal &lhs, const Rhs &rhs)
const mpreal atan2pi(const mpreal &y, const mpreal &x, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal atanpi(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
bool isEqualUlps(const mpreal &a, const mpreal &b, int maxUlps)
const mpreal fmod(const mpreal &x, unsigned long u, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal exp10m1(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
bool isEqualFuzzy(const mpreal &a, const mpreal &b, const mpreal &eps)
mp_prec_t digits2bits(int d)
const mpreal compound(const mpreal &x, long n, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
mpreal & negate(mpreal &x)
const mpreal atan2u(const mpreal &y, const mpreal &x, unsigned long u, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal log2p1(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal beta(const mpreal &z, const mpreal &w, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal tanpi(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
const internal::result_type< Rhs >::type operator/(const mpreal &lhs, const Rhs &rhs)
const mpreal mul_2si(const mpreal &v, long int k, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal acospi(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal log10p1(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal div_2si(const mpreal &v, long int k, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal exp2m1(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
bool iszero(const mpreal &op)
mpreal machine_epsilon(mp_prec_t prec=mpreal::get_default_prec())
const mpreal asinpi(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal log_ui(unsigned long int n, mp_prec_t prec=mpreal::get_default_prec(), mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal frexp(const mpreal &x, mp_exp_t *exp, mp_rnd_t mode=mpreal::get_default_rnd())
const mpreal exp(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
mpreal & setsignbit(mpreal &x, bool minus, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
mpreal maxval(mp_prec_t prec=mpreal::get_default_prec())
const mpreal tanu(const mpreal &x, unsigned long u, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal sinu(const mpreal &x, unsigned long u, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal sqr(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal atanu(const mpreal &x, unsigned long u, mp_rnd_t r=mpreal::get_default_rnd())
const mpreal max(const mpreal &x, const mpreal &y)
const mpreal powr(const mpreal &x, const mpreal &y, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
const mpreal operator>>(const mpreal &v, const unsigned long int k)
const mpreal nextabove(const mpreal &x)
const mpreal pow(const mpreal &a, const unsigned int b, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
static gmp_randstate_t state