00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef __MP_REAL_H__
00070 #define __MP_REAL_H__
00071
00072 #include <string>
00073 #include <iostream>
00074 #include <sstream>
00075 #include <stdexcept>
00076 #include <cfloat>
00077 #include <cmath>
00078
00079 #include <mpfr.h>
00080
00081
00082 #if defined(__GNUC__) && defined(__INTEL_COMPILER)
00083 #define IsInf(x) isinf(x) // Intel ICC compiler on Linux
00084
00085 #elif defined(__GNUC__)
00086 #define IsInf(x) std::isinf(x) // GNU C/C++
00087
00088 #elif defined(_MSC_VER)
00089 #define IsInf(x) (!_finite(x)) // Microsoft Visual C++
00090
00091 #else
00092 #define IsInf(x) std::isinf(x) // Unknown compiler, just hope for C99 conformance
00093 #endif
00094
00095 namespace mpfr {
00096
00097 class mpreal {
00098 private:
00099 mpfr_t mp;
00100
00101 public:
00102 static mp_rnd_t default_rnd;
00103 static mp_prec_t default_prec;
00104 static int default_base;
00105 static int double_bits;
00106
00107 public:
00108
00109 mpreal();
00110 mpreal(const mpreal& u);
00111
00112 mpreal(const mpfr_t u);
00113 mpreal(const mpf_t u);
00114
00115 mpreal(const mpz_t u, mp_prec_t prec = default_prec, mp_rnd_t mode = default_rnd);
00116 mpreal(const mpq_t u, mp_prec_t prec = default_prec, mp_rnd_t mode = default_rnd);
00117 mpreal(const double u, mp_prec_t prec = default_prec, mp_rnd_t mode = default_rnd);
00118 mpreal(const long double u, mp_prec_t prec = default_prec, mp_rnd_t mode = default_rnd);
00119 mpreal(const unsigned long int u, mp_prec_t prec = default_prec, mp_rnd_t mode = default_rnd);
00120 mpreal(const unsigned int u, mp_prec_t prec = default_prec, mp_rnd_t mode = default_rnd);
00121 mpreal(const long int u, mp_prec_t prec = default_prec, mp_rnd_t mode = default_rnd);
00122 mpreal(const int u, mp_prec_t prec = default_prec, mp_rnd_t mode = default_rnd);
00123 mpreal(const char* s, mp_prec_t prec = default_prec, int base = default_base, mp_rnd_t mode = default_rnd);
00124 mpreal(const std::string& s, mp_prec_t prec = default_prec, int base = default_base, mp_rnd_t mode = default_rnd);
00125
00126 ~mpreal();
00127
00128
00129
00130
00131
00132
00133
00134
00135 mpreal& operator=(const mpreal& v);
00136 mpreal& operator=(const mpf_t v);
00137 mpreal& operator=(const mpz_t v);
00138 mpreal& operator=(const mpq_t v);
00139 mpreal& operator=(const long double v);
00140 mpreal& operator=(const double v);
00141 mpreal& operator=(const unsigned long int v);
00142 mpreal& operator=(const unsigned int v);
00143 mpreal& operator=(const long int v);
00144 mpreal& operator=(const int v);
00145 mpreal& operator=(const char* s);
00146
00147
00148 mpreal& operator+=(const mpreal& v);
00149 mpreal& operator+=(const mpf_t v);
00150 mpreal& operator+=(const mpz_t v);
00151 mpreal& operator+=(const mpq_t v);
00152 mpreal& operator+=(const long double u);
00153 mpreal& operator+=(const double u);
00154 mpreal& operator+=(const unsigned long int u);
00155 mpreal& operator+=(const unsigned int u);
00156 mpreal& operator+=(const long int u);
00157 mpreal& operator+=(const int u);
00158 const mpreal operator+() const;
00159 mpreal& operator++ ();
00160 const mpreal operator++ (int);
00161
00162
00163 mpreal& operator-=(const mpreal& v);
00164 mpreal& operator-=(const mpz_t v);
00165 mpreal& operator-=(const mpq_t v);
00166 mpreal& operator-=(const long double u);
00167 mpreal& operator-=(const double u);
00168 mpreal& operator-=(const unsigned long int u);
00169 mpreal& operator-=(const unsigned int u);
00170 mpreal& operator-=(const long int u);
00171 mpreal& operator-=(const int u);
00172 const mpreal operator-() const;
00173 friend const mpreal operator-(const unsigned long int b, const mpreal& a);
00174 friend const mpreal operator-(const unsigned int b, const mpreal& a);
00175 friend const mpreal operator-(const long int b, const mpreal& a);
00176 friend const mpreal operator-(const int b, const mpreal& a);
00177 friend const mpreal operator-(const double b, const mpreal& a);
00178 mpreal& operator-- ();
00179 const mpreal operator-- (int);
00180
00181
00182 mpreal& operator*=(const mpreal& v);
00183 mpreal& operator*=(const mpz_t v);
00184 mpreal& operator*=(const mpq_t v);
00185 mpreal& operator*=(const long double v);
00186 mpreal& operator*=(const double v);
00187 mpreal& operator*=(const unsigned long int v);
00188 mpreal& operator*=(const unsigned int v);
00189 mpreal& operator*=(const long int v);
00190 mpreal& operator*=(const int v);
00191
00192
00193 mpreal& operator/=(const mpreal& v);
00194 mpreal& operator/=(const mpz_t v);
00195 mpreal& operator/=(const mpq_t v);
00196 mpreal& operator/=(const long double v);
00197 mpreal& operator/=(const double v);
00198 mpreal& operator/=(const unsigned long int v);
00199 mpreal& operator/=(const unsigned int v);
00200 mpreal& operator/=(const long int v);
00201 mpreal& operator/=(const int v);
00202 friend const mpreal operator/(const unsigned long int b, const mpreal& a);
00203 friend const mpreal operator/(const unsigned int b, const mpreal& a);
00204 friend const mpreal operator/(const long int b, const mpreal& a);
00205 friend const mpreal operator/(const int b, const mpreal& a);
00206 friend const mpreal operator/(const double b, const mpreal& a);
00207
00208
00209 mpreal& operator<<=(const unsigned long int u);
00210 mpreal& operator<<=(const unsigned int u);
00211 mpreal& operator<<=(const long int u);
00212 mpreal& operator<<=(const int u);
00213
00214
00215 mpreal& operator>>=(const unsigned long int u);
00216 mpreal& operator>>=(const unsigned int u);
00217 mpreal& operator>>=(const long int u);
00218 mpreal& operator>>=(const int u);
00219
00220
00221 friend bool operator > (const mpreal& a, const mpreal& b);
00222 friend bool operator >= (const mpreal& a, const mpreal& b);
00223 friend bool operator < (const mpreal& a, const mpreal& b);
00224 friend bool operator <= (const mpreal& a, const mpreal& b);
00225 friend bool operator == (const mpreal& a, const mpreal& b);
00226 friend bool operator != (const mpreal& a, const mpreal& b);
00227
00228
00229 inline operator long double() const;
00230 inline operator double() const;
00231 inline operator float() const;
00232 inline operator unsigned long() const;
00233 inline operator unsigned int() const;
00234 inline operator long() const;
00235 inline operator int() const;
00236 operator std::string() const;
00237 inline operator mpfr_ptr();
00238
00239
00240 friend const mpreal sqr(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00241 friend const mpreal sqrt(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00242 friend const mpreal sqrt(const unsigned long int v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00243 friend const mpreal cbrt(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00244 friend const mpreal root(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode = mpreal::default_rnd);
00245 friend const mpreal pow(const mpreal& a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00246 friend const mpreal pow(const mpreal& a, const mpz_t b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00247 friend const mpreal pow(const mpreal& a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00248 friend const mpreal pow(const mpreal& a, const long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00249 friend const mpreal pow(const unsigned long int a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00250 friend const mpreal pow(const unsigned long int a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00251 friend const mpreal fabs(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00252
00253 friend const mpreal abs(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00254 friend const mpreal dim(const mpreal& a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00255 friend inline const mpreal mul_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode = mpreal::default_rnd);
00256 friend inline const mpreal mul_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode = mpreal::default_rnd);
00257 friend inline const mpreal div_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode = mpreal::default_rnd);
00258 friend inline const mpreal div_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode = mpreal::default_rnd);
00259 friend int cmpabs(const mpreal& a,const mpreal& b);
00260
00261 friend const mpreal log (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00262 friend const mpreal log2 (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00263 friend const mpreal log10(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00264 friend const mpreal exp (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00265 friend const mpreal exp2 (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00266 friend const mpreal exp10(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00267 friend const mpreal log1p (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00268 friend const mpreal expm1 (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00269
00270 friend const mpreal cos(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00271 friend const mpreal sin(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00272 friend const mpreal tan(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00273 friend const mpreal sec(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00274 friend const mpreal csc(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00275 friend const mpreal cot(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00276 friend int sin_cos(mpreal& s, mpreal& c, const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00277
00278 friend const mpreal acos (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00279 friend const mpreal asin (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00280 friend const mpreal atan (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00281 friend const mpreal atan2 (const mpreal& y, const mpreal& x, mp_rnd_t rnd_mode = mpreal::default_rnd);
00282 friend const mpreal cosh (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00283 friend const mpreal sinh (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00284 friend const mpreal tanh (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00285 friend const mpreal sech (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00286 friend const mpreal csch (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00287 friend const mpreal coth (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00288 friend const mpreal acosh (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00289 friend const mpreal asinh (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00290 friend const mpreal atanh (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00291 friend const mpreal hypot (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::default_rnd);
00292
00293 friend const mpreal fac_ui (unsigned long int v, mp_prec_t prec = mpreal::default_prec, mp_rnd_t rnd_mode = mpreal::default_rnd);
00294 friend const mpreal eint (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00295
00296 friend const mpreal gamma (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00297 friend const mpreal lngamma (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00298 friend const mpreal lgamma (const mpreal& v, int *signp = 0, mp_rnd_t rnd_mode = mpreal::default_rnd);
00299 friend const mpreal zeta (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00300 friend const mpreal erf (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00301 friend const mpreal erfc (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00302 friend const mpreal _j0 (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00303 friend const mpreal _j1 (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00304 friend const mpreal _jn (long n, const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00305 friend const mpreal _y0 (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00306 friend const mpreal _y1 (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00307 friend const mpreal _yn (long n, const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00308 friend const mpreal fma (const mpreal& v1, const mpreal& v2, const mpreal& v3, mp_rnd_t rnd_mode = mpreal::default_rnd);
00309 friend const mpreal fms (const mpreal& v1, const mpreal& v2, const mpreal& v3, mp_rnd_t rnd_mode = mpreal::default_rnd);
00310 friend const mpreal agm (const mpreal& v1, const mpreal& v2, mp_rnd_t rnd_mode = mpreal::default_rnd);
00311 friend const mpreal sum (const mpreal tab[], unsigned long int n, mp_rnd_t rnd_mode = mpreal::default_rnd);
00312 friend int sgn(const mpreal& v);
00313
00314
00315 #if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
00316 friend int sinh_cosh(mpreal& s, mpreal& c, const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00317 friend const mpreal li2(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00318 friend const mpreal fmod (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::default_rnd);
00319 friend const mpreal rec_sqrt(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00320 #endif
00321
00322
00323 #if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
00324 friend const mpreal digamma(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00325 friend const mpreal ai(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00326 friend const mpreal urandom (gmp_randstate_t& state,mp_rnd_t rnd_mode = mpreal::default_rnd);
00327 friend bool _isregular(const mpreal& v);
00328 #endif
00329
00330
00331 friend const mpreal frexp(const mpreal& v, mp_exp_t* exp);
00332 friend const mpreal ldexp(const mpreal& v, mp_exp_t exp);
00333
00334
00335
00336 friend const mpreal modf(const mpreal& v, mpreal& n);
00337
00338
00339
00340 friend const mpreal const_log2 (mp_prec_t prec = mpreal::default_prec, mp_rnd_t rnd_mode = mpreal::default_rnd);
00341 friend const mpreal const_pi (mp_prec_t prec = mpreal::default_prec, mp_rnd_t rnd_mode = mpreal::default_rnd);
00342 friend const mpreal const_euler (mp_prec_t prec = mpreal::default_prec, mp_rnd_t rnd_mode = mpreal::default_rnd);
00343 friend const mpreal const_catalan (mp_prec_t prec = mpreal::default_prec, mp_rnd_t rnd_mode = mpreal::default_rnd);
00344
00345 friend const mpreal const_infinity(int sign = 1, mp_prec_t prec = mpreal::default_prec, mp_rnd_t rnd_mode = mpreal::default_rnd);
00346
00347
00348 friend std::ostream& operator<<(std::ostream& os, const mpreal& v);
00349 friend std::istream& operator>>(std::istream& is, mpreal& v);
00350
00351
00352 friend const mpreal rint (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00353 friend const mpreal ceil (const mpreal& v);
00354 friend const mpreal floor(const mpreal& v);
00355 friend const mpreal round(const mpreal& v);
00356 friend const mpreal trunc(const mpreal& v);
00357 friend const mpreal rint_ceil (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00358 friend const mpreal rint_floor(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00359 friend const mpreal rint_round(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00360 friend const mpreal rint_trunc(const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00361 friend const mpreal frac (const mpreal& v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00362 friend const mpreal remainder (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::default_rnd);
00363 friend const mpreal remquo (long* q, const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = mpreal::default_rnd);
00364
00365
00366 friend const mpreal nexttoward (const mpreal& x, const mpreal& y);
00367 friend const mpreal nextabove (const mpreal& x);
00368 friend const mpreal nextbelow (const mpreal& x);
00369
00370
00371 friend const mpreal urandomb (gmp_randstate_t& state);
00372
00373
00374 #if (MPFR_VERSION <= MPFR_VERSION_NUM(2,4,2))
00375 friend const mpreal random2 (mp_size_t size, mp_exp_t exp);
00376 #endif
00377
00378
00379 friend bool _isnan(const mpreal& v);
00380 friend bool _isinf(const mpreal& v);
00381 friend bool _isnum(const mpreal& v);
00382 friend bool _iszero(const mpreal& v);
00383 friend bool _isint(const mpreal& v);
00384
00385
00386 inline mp_prec_t get_prec() const;
00387 inline void set_prec(mp_prec_t prec, mp_rnd_t rnd_mode = default_rnd);
00388
00389
00390 void set_inf(int sign = +1);
00391 void set_nan();
00392
00393
00394 void set_sign(int sign, mp_rnd_t rnd_mode = default_rnd);
00395
00396
00397 mp_exp_t get_exp();
00398 int set_exp(mp_exp_t e);
00399 int check_range (int t, mp_rnd_t rnd_mode = default_rnd);
00400 int subnormalize (int t,mp_rnd_t rnd_mode = default_rnd);
00401
00402
00403 inline bool fits_in_bits(double x, int n);
00404
00405
00406 static void set_default_prec(mp_prec_t prec);
00407 static mp_prec_t get_default_prec();
00408 static void set_default_base(int base);
00409 static int get_default_base();
00410 static void set_double_bits(int dbits);
00411 static int get_double_bits();
00412 static void set_default_rnd(mp_rnd_t rnd_mode);
00413 static mp_rnd_t get_default_rnd();
00414 static mp_exp_t get_emin (void);
00415 static mp_exp_t get_emax (void);
00416 static mp_exp_t get_emin_min (void);
00417 static mp_exp_t get_emin_max (void);
00418 static mp_exp_t get_emax_min (void);
00419 static mp_exp_t get_emax_max (void);
00420 static int set_emin (mp_exp_t exp);
00421 static int set_emax (mp_exp_t exp);
00422
00423
00424
00425
00426 std::string to_string(size_t n = 0, int b = default_base, mp_rnd_t mode = default_rnd) const;
00427
00428
00429 friend void swap(mpreal& x, mpreal& y);
00430
00431
00432
00433 #ifndef max
00434 friend const mpreal max(const mpreal& x, const mpreal& y);
00435 #endif
00436
00437 #ifndef min
00438 friend const mpreal min(const mpreal& x, const mpreal& y);
00439 #endif
00440
00441 friend const mpreal fmax(const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = default_rnd);
00442 friend const mpreal fmin(const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode = default_rnd);
00443
00444 private:
00445
00446 static bool is_custom_malloc;
00447 static void *mpreal_allocate (size_t alloc_size);
00448 static void *mpreal_reallocate (void *ptr, size_t old_size, size_t new_size);
00449 static void mpreal_free (void *ptr, size_t size);
00450 inline static void set_custom_malloc (void);
00451 };
00452
00454
00455 class conversion_overflow : public std::exception {
00456 public:
00457 std::string why() { return "inexact conversion from floating point"; }
00458 };
00459
00461
00462 const mpreal operator+(const mpreal& a, const mpreal& b);
00463
00464
00465 const mpreal operator+(const mpreal& a, const mpz_t b);
00466 const mpreal operator+(const mpreal& a, const mpq_t b);
00467 const mpreal operator+(const mpreal& a, const long double b);
00468 const mpreal operator+(const mpreal& a, const double b);
00469 const mpreal operator+(const mpreal& a, const unsigned long int b);
00470 const mpreal operator+(const mpreal& a, const unsigned int b);
00471 const mpreal operator+(const mpreal& a, const long int b);
00472 const mpreal operator+(const mpreal& a, const int b);
00473 const mpreal operator+(const mpreal& a, const char* b);
00474 const mpreal operator+(const char* a, const mpreal& b);
00475 const std::string operator+(const mpreal& a, const std::string b);
00476 const std::string operator+(const std::string a, const mpreal& b);
00477
00478 const mpreal operator+(const mpz_t b, const mpreal& a);
00479 const mpreal operator+(const mpq_t b, const mpreal& a);
00480 const mpreal operator+(const long double b, const mpreal& a);
00481 const mpreal operator+(const double b, const mpreal& a);
00482 const mpreal operator+(const unsigned long int b, const mpreal& a);
00483 const mpreal operator+(const unsigned int b, const mpreal& a);
00484 const mpreal operator+(const long int b, const mpreal& a);
00485 const mpreal operator+(const int b, const mpreal& a);
00486
00488
00489 const mpreal operator-(const mpreal& a, const mpreal& b);
00490
00491
00492 const mpreal operator-(const mpreal& a, const mpz_t b);
00493 const mpreal operator-(const mpreal& a, const mpq_t b);
00494 const mpreal operator-(const mpreal& a, const long double b);
00495 const mpreal operator-(const mpreal& a, const double b);
00496 const mpreal operator-(const mpreal& a, const unsigned long int b);
00497 const mpreal operator-(const mpreal& a, const unsigned int b);
00498 const mpreal operator-(const mpreal& a, const long int b);
00499 const mpreal operator-(const mpreal& a, const int b);
00500 const mpreal operator-(const mpreal& a, const char* b);
00501 const mpreal operator-(const char* a, const mpreal& b);
00502
00503 const mpreal operator-(const mpz_t b, const mpreal& a);
00504 const mpreal operator-(const mpq_t b, const mpreal& a);
00505 const mpreal operator-(const long double b, const mpreal& a);
00506
00507
00509
00510 const mpreal operator*(const mpreal& a, const mpreal& b);
00511
00512
00513 const mpreal operator*(const mpreal& a, const mpz_t b);
00514 const mpreal operator*(const mpreal& a, const mpq_t b);
00515 const mpreal operator*(const mpreal& a, const long double b);
00516 const mpreal operator*(const mpreal& a, const double b);
00517 const mpreal operator*(const mpreal& a, const unsigned long int b);
00518 const mpreal operator*(const mpreal& a, const unsigned int b);
00519 const mpreal operator*(const mpreal& a, const long int b);
00520 const mpreal operator*(const mpreal& a, const int b);
00521
00522 const mpreal operator*(const mpz_t b, const mpreal& a);
00523 const mpreal operator*(const mpq_t b, const mpreal& a);
00524 const mpreal operator*(const long double b, const mpreal& a);
00525 const mpreal operator*(const double b, const mpreal& a);
00526 const mpreal operator*(const unsigned long int b, const mpreal& a);
00527 const mpreal operator*(const unsigned int b, const mpreal& a);
00528 const mpreal operator*(const long int b, const mpreal& a);
00529 const mpreal operator*(const int b, const mpreal& a);
00530
00532
00533 const mpreal operator/(const mpreal& a, const mpreal& b);
00534
00535
00536 const mpreal operator/(const mpreal& a, const mpz_t b);
00537 const mpreal operator/(const mpreal& a, const mpq_t b);
00538 const mpreal operator/(const mpreal& a, const long double b);
00539 const mpreal operator/(const mpreal& a, const double b);
00540 const mpreal operator/(const mpreal& a, const unsigned long int b);
00541 const mpreal operator/(const mpreal& a, const unsigned int b);
00542 const mpreal operator/(const mpreal& a, const long int b);
00543 const mpreal operator/(const mpreal& a, const int b);
00544
00545 const mpreal operator/(const long double b, const mpreal& a);
00546
00548
00549 const mpreal operator<<(const mpreal& v, const unsigned long int k);
00550 const mpreal operator<<(const mpreal& v, const unsigned int k);
00551 const mpreal operator<<(const mpreal& v, const long int k);
00552 const mpreal operator<<(const mpreal& v, const int k);
00553
00554 const mpreal operator>>(const mpreal& v, const unsigned long int k);
00555 const mpreal operator>>(const mpreal& v, const unsigned int k);
00556 const mpreal operator>>(const mpreal& v, const long int k);
00557 const mpreal operator>>(const mpreal& v, const int k);
00558
00560
00561 bool operator < (const mpreal& a, const unsigned long int b);
00562 bool operator < (const mpreal& a, const unsigned int b);
00563 bool operator < (const mpreal& a, const long int b);
00564 bool operator < (const mpreal& a, const int b);
00565 bool operator < (const mpreal& a, const long double b);
00566 bool operator < (const mpreal& a, const double b);
00567
00568 bool operator < (const unsigned long int a,const mpreal& b);
00569 bool operator < (const unsigned int a, const mpreal& b);
00570 bool operator < (const long int a, const mpreal& b);
00571 bool operator < (const int a, const mpreal& b);
00572 bool operator < (const long double a, const mpreal& b);
00573 bool operator < (const double a, const mpreal& b);
00574
00575 bool operator > (const mpreal& a, const unsigned long int b);
00576 bool operator > (const mpreal& a, const unsigned int b);
00577 bool operator > (const mpreal& a, const long int b);
00578 bool operator > (const mpreal& a, const int b);
00579 bool operator > (const mpreal& a, const long double b);
00580 bool operator > (const mpreal& a, const double b);
00581
00582 bool operator > (const unsigned long int a,const mpreal& b);
00583 bool operator > (const unsigned int a, const mpreal& b);
00584 bool operator > (const long int a, const mpreal& b);
00585 bool operator > (const int a, const mpreal& b);
00586 bool operator > (const long double a, const mpreal& b);
00587 bool operator > (const double a, const mpreal& b);
00588
00589 bool operator >= (const mpreal& a, const unsigned long int b);
00590 bool operator >= (const mpreal& a, const unsigned int b);
00591 bool operator >= (const mpreal& a, const long int b);
00592 bool operator >= (const mpreal& a, const int b);
00593 bool operator >= (const mpreal& a, const long double b);
00594 bool operator >= (const mpreal& a, const double b);
00595
00596 bool operator >= (const unsigned long int a,const mpreal& b);
00597 bool operator >= (const unsigned int a, const mpreal& b);
00598 bool operator >= (const long int a, const mpreal& b);
00599 bool operator >= (const int a, const mpreal& b);
00600 bool operator >= (const long double a, const mpreal& b);
00601 bool operator >= (const double a, const mpreal& b);
00602
00603 bool operator <= (const mpreal& a, const unsigned long int b);
00604 bool operator <= (const mpreal& a, const unsigned int b);
00605 bool operator <= (const mpreal& a, const long int b);
00606 bool operator <= (const mpreal& a, const int b);
00607 bool operator <= (const mpreal& a, const long double b);
00608 bool operator <= (const mpreal& a, const double b);
00609
00610 bool operator <= (const unsigned long int a,const mpreal& b);
00611 bool operator <= (const unsigned int a, const mpreal& b);
00612 bool operator <= (const long int a, const mpreal& b);
00613 bool operator <= (const int a, const mpreal& b);
00614 bool operator <= (const long double a, const mpreal& b);
00615 bool operator <= (const double a, const mpreal& b);
00616
00617 bool operator == (const mpreal& a, const unsigned long int b);
00618 bool operator == (const mpreal& a, const unsigned int b);
00619 bool operator == (const mpreal& a, const long int b);
00620 bool operator == (const mpreal& a, const int b);
00621 bool operator == (const mpreal& a, const long double b);
00622 bool operator == (const mpreal& a, const double b);
00623
00624 bool operator == (const unsigned long int a,const mpreal& b);
00625 bool operator == (const unsigned int a, const mpreal& b);
00626 bool operator == (const long int a, const mpreal& b);
00627 bool operator == (const int a, const mpreal& b);
00628 bool operator == (const long double a, const mpreal& b);
00629 bool operator == (const double a, const mpreal& b);
00630
00631 bool operator != (const mpreal& a, const unsigned long int b);
00632 bool operator != (const mpreal& a, const unsigned int b);
00633 bool operator != (const mpreal& a, const long int b);
00634 bool operator != (const mpreal& a, const int b);
00635 bool operator != (const mpreal& a, const long double b);
00636 bool operator != (const mpreal& a, const double b);
00637
00638 bool operator != (const unsigned long int a,const mpreal& b);
00639 bool operator != (const unsigned int a, const mpreal& b);
00640 bool operator != (const long int a, const mpreal& b);
00641 bool operator != (const int a, const mpreal& b);
00642 bool operator != (const long double a, const mpreal& b);
00643 bool operator != (const double a, const mpreal& b);
00644
00646
00647 const mpreal sqrt(const unsigned int v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00648 const mpreal sqrt(const long int v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00649 const mpreal sqrt(const int v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00650 const mpreal sqrt(const long double v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00651 const mpreal sqrt(const double v, mp_rnd_t rnd_mode = mpreal::default_rnd);
00652
00654
00655 const mpreal pow(const mpreal& a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00656 const mpreal pow(const mpreal& a, const int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00657 const mpreal pow(const mpreal& a, const long double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00658 const mpreal pow(const mpreal& a, const double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00659
00660 const mpreal pow(const unsigned int a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00661 const mpreal pow(const long int a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00662 const mpreal pow(const int a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00663 const mpreal pow(const long double a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00664 const mpreal pow(const double a, const mpreal& b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00665
00666 const mpreal pow(const unsigned long int a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00667 const mpreal pow(const unsigned long int a, const long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00668 const mpreal pow(const unsigned long int a, const int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00669 const mpreal pow(const unsigned long int a, const long double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00670 const mpreal pow(const unsigned long int a, const double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00671
00672 const mpreal pow(const unsigned int a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00673 const mpreal pow(const unsigned int a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00674 const mpreal pow(const unsigned int a, const long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00675 const mpreal pow(const unsigned int a, const int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00676 const mpreal pow(const unsigned int a, const long double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00677 const mpreal pow(const unsigned int a, const double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00678
00679 const mpreal pow(const long int a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00680 const mpreal pow(const long int a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00681 const mpreal pow(const long int a, const long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00682 const mpreal pow(const long int a, const int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00683 const mpreal pow(const long int a, const long double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00684 const mpreal pow(const long int a, const double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00685
00686 const mpreal pow(const int a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00687 const mpreal pow(const int a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00688 const mpreal pow(const int a, const long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00689 const mpreal pow(const int a, const int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00690 const mpreal pow(const int a, const long double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00691 const mpreal pow(const int a, const double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00692
00693 const mpreal pow(const long double a, const long double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00694 const mpreal pow(const long double a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00695 const mpreal pow(const long double a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00696 const mpreal pow(const long double a, const long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00697 const mpreal pow(const long double a, const int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00698
00699 const mpreal pow(const double a, const double b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00700 const mpreal pow(const double a, const unsigned long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00701 const mpreal pow(const double a, const unsigned int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00702 const mpreal pow(const double a, const long int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00703 const mpreal pow(const double a, const int b, mp_rnd_t rnd_mode = mpreal::default_rnd);
00704
00706
00707 inline const mpreal machine_epsilon(mp_prec_t prec = mpreal::default_prec);
00708 inline const mpreal mpreal_min(mp_prec_t prec = mpreal::default_prec);
00709 inline const mpreal mpreal_max(mp_prec_t prec = mpreal::default_prec);
00710
00712
00714
00716
00717 inline mpreal& mpreal::operator=(const mpreal& v)
00718 {
00719 if (this!= &v)
00720 {
00721 mpfr_set_prec(mp,mpfr_get_prec(v.mp));
00722 mpfr_set(mp,v.mp,default_rnd);
00723 }
00724 return *this;
00725 }
00726
00727 inline mpreal& mpreal::operator=(const mpf_t v)
00728 {
00729 mpfr_set_f(mp,v,default_rnd);
00730 return *this;
00731 }
00732
00733 inline mpreal& mpreal::operator=(const mpz_t v)
00734 {
00735 mpfr_set_z(mp,v,default_rnd);
00736 return *this;
00737 }
00738
00739 inline mpreal& mpreal::operator=(const mpq_t v)
00740 {
00741 mpfr_set_q(mp,v,default_rnd);
00742 return *this;
00743 }
00744
00745 inline mpreal& mpreal::operator=(const long double v)
00746 {
00747 mpfr_set_ld(mp,v,default_rnd);
00748 return *this;
00749 }
00750
00751 inline mpreal& mpreal::operator=(const double v)
00752 {
00753 if(double_bits == -1 || fits_in_bits(v, double_bits))
00754 {
00755 mpfr_set_d(mp,v,default_rnd);
00756 }
00757 else
00758 throw conversion_overflow();
00759
00760 return *this;
00761 }
00762
00763 inline mpreal& mpreal::operator=(const unsigned long int v)
00764 {
00765 mpfr_set_ui(mp,v,default_rnd);
00766 return *this;
00767 }
00768
00769 inline mpreal& mpreal::operator=(const unsigned int v)
00770 {
00771 mpfr_set_ui(mp,v,default_rnd);
00772 return *this;
00773 }
00774
00775 inline mpreal& mpreal::operator=(const long int v)
00776 {
00777 mpfr_set_si(mp,v,default_rnd);
00778 return *this;
00779 }
00780
00781 inline mpreal& mpreal::operator=(const int v)
00782 {
00783 mpfr_set_si(mp,v,default_rnd);
00784 return *this;
00785 }
00786
00788
00789 inline mpreal& mpreal::operator+=(const mpreal& v)
00790 {
00791 mpfr_add(mp,mp,v.mp,default_rnd);
00792 return *this;
00793 }
00794
00795 inline mpreal& mpreal::operator+=(const mpf_t u)
00796 {
00797 *this += mpreal(u);
00798 return *this;
00799 }
00800
00801 inline mpreal& mpreal::operator+=(const mpz_t u)
00802 {
00803 mpfr_add_z(mp,mp,u,default_rnd);
00804 return *this;
00805 }
00806
00807 inline mpreal& mpreal::operator+=(const mpq_t u)
00808 {
00809 mpfr_add_q(mp,mp,u,default_rnd);
00810 return *this;
00811 }
00812
00813 inline mpreal& mpreal::operator+= (const long double u)
00814 {
00815 return *this += mpreal(u);
00816 }
00817
00818 inline mpreal& mpreal::operator+= (const double u)
00819 {
00820 #if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
00821 mpfr_add_d(mp,mp,u,default_rnd);
00822 return *this;
00823 #else
00824 return *this += mpreal(u);
00825 #endif
00826 }
00827
00828 inline mpreal& mpreal::operator+=(const unsigned long int u)
00829 {
00830 mpfr_add_ui(mp,mp,u,default_rnd);
00831 return *this;
00832 }
00833
00834 inline mpreal& mpreal::operator+=(const unsigned int u)
00835 {
00836 mpfr_add_ui(mp,mp,u,default_rnd);
00837 return *this;
00838 }
00839
00840 inline mpreal& mpreal::operator+=(const long int u)
00841 {
00842 mpfr_add_si(mp,mp,u,default_rnd);
00843 return *this;
00844 }
00845
00846 inline mpreal& mpreal::operator+=(const int u)
00847 {
00848 mpfr_add_si(mp,mp,u,default_rnd);
00849 return *this;
00850 }
00851
00852 inline const mpreal mpreal::operator+()const
00853 {
00854 return mpreal(*this);
00855 }
00856
00857 inline const mpreal operator+(const mpreal& a, const mpreal& b)
00858 {
00859
00860 if(a.get_prec()>b.get_prec()) return mpreal(a) += b;
00861 else return mpreal(b) += a;
00862 }
00863
00864 inline const std::string operator+(const mpreal& a, const std::string b)
00865 {
00866 return (std::string)a+b;
00867 }
00868
00869 inline const std::string operator+(const std::string a, const mpreal& b)
00870 {
00871 return a+(std::string)b;
00872 }
00873
00874 inline const mpreal operator+(const mpreal& a, const mpz_t b)
00875 {
00876 return mpreal(a) += b;
00877 }
00878
00879 inline const mpreal operator+(const mpreal& a, const char* b)
00880 {
00881 return a+mpreal(b);
00882 }
00883
00884 inline const mpreal operator+(const char* a, const mpreal& b)
00885 {
00886 return mpreal(a)+b;
00887
00888 }
00889
00890 inline const mpreal operator+(const mpreal& a, const mpq_t b)
00891 {
00892 return mpreal(a) += b;
00893 }
00894
00895 inline const mpreal operator+(const mpreal& a, const long double b)
00896 {
00897 return mpreal(a) += b;
00898 }
00899
00900 inline const mpreal operator+(const mpreal& a, const double b)
00901 {
00902 return mpreal(a) += b;
00903 }
00904
00905 inline const mpreal operator+(const mpreal& a, const unsigned long int b)
00906 {
00907 return mpreal(a) += b;
00908 }
00909
00910 inline const mpreal operator+(const mpreal& a, const unsigned int b)
00911 {
00912 return mpreal(a) += b;
00913 }
00914
00915 inline const mpreal operator+(const mpreal& a, const long int b)
00916 {
00917 return mpreal(a) += b;
00918 }
00919
00920 inline const mpreal operator+(const mpreal& a, const int b)
00921 {
00922 return mpreal(a) += b;
00923 }
00924
00925 inline const mpreal operator+(const mpz_t b, const mpreal& a)
00926 {
00927 return mpreal(a) += b;
00928 }
00929
00930 inline const mpreal operator+(const mpq_t b, const mpreal& a)
00931 {
00932 return mpreal(a) += b;
00933 }
00934
00935 inline const mpreal operator+(const long double b, const mpreal& a)
00936 {
00937 return mpreal(a) += b;
00938 }
00939
00940 inline const mpreal operator+(const double b, const mpreal& a)
00941 {
00942 return mpreal(a) += b;
00943 }
00944
00945 inline const mpreal operator+(const unsigned long int b, const mpreal& a)
00946 {
00947 return mpreal(a) += b;
00948 }
00949
00950 inline const mpreal operator+(const unsigned int b, const mpreal& a)
00951 {
00952 return mpreal(a) += b;
00953 }
00954
00955 inline const mpreal operator+(const long int b, const mpreal& a)
00956 {
00957 return mpreal(a) += b;
00958 }
00959
00960 inline const mpreal operator+(const int b, const mpreal& a)
00961 {
00962 return mpreal(a) += b;
00963 }
00964
00965 inline mpreal& mpreal::operator++()
00966 {
00967 *this += 1;
00968 return *this;
00969 }
00970
00971 inline const mpreal mpreal::operator++ (int)
00972 {
00973 mpreal x(*this);
00974 *this += 1;
00975 return x;
00976 }
00977
00978 inline mpreal& mpreal::operator--()
00979 {
00980 *this -= 1;
00981 return *this;
00982 }
00983
00984 inline const mpreal mpreal::operator-- (int)
00985 {
00986 mpreal x(*this);
00987 *this -= 1;
00988 return x;
00989 }
00990
00992
00993 inline mpreal& mpreal::operator-= (const mpreal& v)
00994 {
00995 mpfr_sub(mp,mp,v.mp,default_rnd);
00996 return *this;
00997 }
00998
00999 inline mpreal& mpreal::operator-=(const mpz_t v)
01000 {
01001 mpfr_sub_z(mp,mp,v,default_rnd);
01002 return *this;
01003 }
01004
01005 inline mpreal& mpreal::operator-=(const mpq_t v)
01006 {
01007 mpfr_sub_q(mp,mp,v,default_rnd);
01008 return *this;
01009 }
01010
01011 inline mpreal& mpreal::operator-=(const long double v)
01012 {
01013 return *this -= mpreal(v);
01014 }
01015
01016 inline mpreal& mpreal::operator-=(const double v)
01017 {
01018 #if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
01019 mpfr_sub_d(mp,mp,v,default_rnd);
01020 return *this;
01021 #else
01022 return *this -= mpreal(v);
01023 #endif
01024 }
01025
01026 inline mpreal& mpreal::operator-=(const unsigned long int v)
01027 {
01028 mpfr_sub_ui(mp,mp,v,default_rnd);
01029 return *this;
01030 }
01031
01032 inline mpreal& mpreal::operator-=(const unsigned int v)
01033 {
01034 mpfr_sub_ui(mp,mp,v,default_rnd);
01035 return *this;
01036 }
01037
01038 inline mpreal& mpreal::operator-=(const long int v)
01039 {
01040 mpfr_sub_si(mp,mp,v,default_rnd);
01041 return *this;
01042 }
01043
01044 inline mpreal& mpreal::operator-=(const int v)
01045 {
01046 mpfr_sub_si(mp,mp,v,default_rnd);
01047 return *this;
01048 }
01049
01050 inline const mpreal mpreal::operator-()const
01051 {
01052 mpreal u(*this);
01053 mpfr_neg(u.mp,u.mp,default_rnd);
01054 return u;
01055 }
01056
01057 inline const mpreal operator-(const mpreal& a, const mpreal& b)
01058 {
01059
01060 if(a.get_prec()>b.get_prec()) return mpreal(a) -= b;
01061 else return -(mpreal(b) -= a);
01062 }
01063
01064 inline const mpreal operator-(const mpreal& a, const mpz_t b)
01065 {
01066 return mpreal(a) -= b;
01067 }
01068
01069 inline const mpreal operator-(const mpreal& a, const mpq_t b)
01070 {
01071 return mpreal(a) -= b;
01072 }
01073
01074 inline const mpreal operator-(const mpreal& a, const long double b)
01075 {
01076 return mpreal(a) -= b;
01077 }
01078
01079 inline const mpreal operator-(const mpreal& a, const double b)
01080 {
01081 return mpreal(a) -= b;
01082 }
01083
01084 inline const mpreal operator-(const mpreal& a, const unsigned long int b)
01085 {
01086 return mpreal(a) -= b;
01087 }
01088
01089 inline const mpreal operator-(const mpreal& a, const unsigned int b)
01090 {
01091 return mpreal(a) -= b;
01092 }
01093
01094 inline const mpreal operator-(const mpreal& a, const long int b)
01095 {
01096 return mpreal(a) -= b;
01097 }
01098
01099 inline const mpreal operator-(const mpreal& a, const int b)
01100 {
01101 return mpreal(a) -= b;
01102 }
01103
01104 inline const mpreal operator-(const mpz_t b, const mpreal& a)
01105 {
01106 return -(mpreal(a) -= b);
01107 }
01108
01109 inline const mpreal operator-(const mpq_t b, const mpreal& a)
01110 {
01111 return -(mpreal(a) -= b);
01112 }
01113
01114 inline const mpreal operator-(const long double b, const mpreal& a)
01115 {
01116 return -(mpreal(a) -= b);
01117 }
01118
01119 inline const mpreal operator-(const double b, const mpreal& a)
01120 {
01121 #if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
01122 mpreal x(a);
01123 mpfr_d_sub(x.mp,b,a.mp,mpreal::default_rnd);
01124 return x;
01125 #else
01126 return -(mpreal(a) -= b);
01127 #endif
01128 }
01129
01130 inline const mpreal operator-(const unsigned long int b, const mpreal& a)
01131 {
01132 mpreal x(a);
01133 mpfr_ui_sub(x.mp,b,a.mp,mpreal::default_rnd);
01134 return x;
01135 }
01136
01137 inline const mpreal operator-(const unsigned int b, const mpreal& a)
01138 {
01139 mpreal x(a);
01140 mpfr_ui_sub(x.mp,b,a.mp,mpreal::default_rnd);
01141 return x;
01142 }
01143
01144 inline const mpreal operator-(const long int b, const mpreal& a)
01145 {
01146 mpreal x(a);
01147 mpfr_si_sub(x.mp,b,a.mp,mpreal::default_rnd);
01148 return x;
01149 }
01150
01151 inline const mpreal operator-(const int b, const mpreal& a)
01152 {
01153 mpreal x(a);
01154 mpfr_si_sub(x.mp,b,a.mp,mpreal::default_rnd);
01155 return x;
01156 }
01157
01158 inline const mpreal operator-(const mpreal& a, const char* b)
01159 {
01160 return a-mpreal(b);
01161 }
01162
01163 inline const mpreal operator-(const char* a, const mpreal& b)
01164 {
01165 return mpreal(a)-b;
01166 }
01167
01169
01170 inline mpreal& mpreal::operator*= (const mpreal& v)
01171 {
01172 mpfr_mul(mp,mp,v.mp,default_rnd);
01173 return *this;
01174 }
01175
01176 inline mpreal& mpreal::operator*=(const mpz_t v)
01177 {
01178 mpfr_mul_z(mp,mp,v,default_rnd);
01179 return *this;
01180 }
01181
01182 inline mpreal& mpreal::operator*=(const mpq_t v)
01183 {
01184 mpfr_mul_q(mp,mp,v,default_rnd);
01185 return *this;
01186 }
01187
01188 inline mpreal& mpreal::operator*=(const long double v)
01189 {
01190 return *this *= mpreal(v);
01191 }
01192
01193 inline mpreal& mpreal::operator*=(const double v)
01194 {
01195 #if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
01196 mpfr_mul_d(mp,mp,v,default_rnd);
01197 return *this;
01198 #else
01199 return *this *= mpreal(v);
01200 #endif
01201 }
01202
01203 inline mpreal& mpreal::operator*=(const unsigned long int v)
01204 {
01205 mpfr_mul_ui(mp,mp,v,default_rnd);
01206 return *this;
01207 }
01208
01209 inline mpreal& mpreal::operator*=(const unsigned int v)
01210 {
01211 mpfr_mul_ui(mp,mp,v,default_rnd);
01212 return *this;
01213 }
01214
01215 inline mpreal& mpreal::operator*=(const long int v)
01216 {
01217 mpfr_mul_si(mp,mp,v,default_rnd);
01218 return *this;
01219 }
01220
01221 inline mpreal& mpreal::operator*=(const int v)
01222 {
01223 mpfr_mul_si(mp,mp,v,default_rnd);
01224 return *this;
01225 }
01226
01227 inline const mpreal operator*(const mpreal& a, const mpreal& b)
01228 {
01229
01230 if(a.get_prec()>b.get_prec()) return mpreal(a) *= b;
01231 else return mpreal(b) *= a;
01232 }
01233
01234 inline const mpreal operator*(const mpreal& a, const mpz_t b)
01235 {
01236 return mpreal(a) *= b;
01237 }
01238
01239 inline const mpreal operator*(const mpreal& a, const mpq_t b)
01240 {
01241 return mpreal(a) *= b;
01242 }
01243
01244 inline const mpreal operator*(const mpreal& a, const long double b)
01245 {
01246 return mpreal(a) *= b;
01247 }
01248
01249 inline const mpreal operator*(const mpreal& a, const double b)
01250 {
01251 return mpreal(a) *= b;
01252 }
01253
01254 inline const mpreal operator*(const mpreal& a, const unsigned long int b)
01255 {
01256 return mpreal(a) *= b;
01257 }
01258
01259 inline const mpreal operator*(const mpreal& a, const unsigned int b)
01260 {
01261 return mpreal(a) *= b;
01262 }
01263
01264 inline const mpreal operator*(const mpreal& a, const long int b)
01265 {
01266 return mpreal(a) *= b;
01267 }
01268
01269 inline const mpreal operator*(const mpreal& a, const int b)
01270 {
01271 return mpreal(a) *= b;
01272 }
01273
01274 inline const mpreal operator*(const mpz_t b, const mpreal& a)
01275 {
01276 return mpreal(a) *= b;
01277 }
01278
01279 inline const mpreal operator*(const mpq_t b, const mpreal& a)
01280 {
01281 return mpreal(a) *= b;
01282 }
01283
01284 inline const mpreal operator*(const long double b, const mpreal& a)
01285 {
01286 return mpreal(a) *= b;
01287 }
01288
01289 inline const mpreal operator*(const double b, const mpreal& a)
01290 {
01291 return mpreal(a) *= b;
01292 }
01293
01294 inline const mpreal operator*(const unsigned long int b, const mpreal& a)
01295 {
01296 return mpreal(a) *= b;
01297 }
01298
01299 inline const mpreal operator*(const unsigned int b, const mpreal& a)
01300 {
01301 return mpreal(a) *= b;
01302 }
01303
01304 inline const mpreal operator*(const long int b, const mpreal& a)
01305 {
01306 return mpreal(a) *= b;
01307 }
01308
01309 inline const mpreal operator*(const int b, const mpreal& a)
01310 {
01311 return mpreal(a) *= b;
01312 }
01313
01315
01316 inline mpreal& mpreal::operator/=(const mpreal& v)
01317 {
01318 mpfr_div(mp,mp,v.mp,default_rnd);
01319 return *this;
01320 }
01321
01322 inline mpreal& mpreal::operator/=(const mpz_t v)
01323 {
01324 mpfr_div_z(mp,mp,v,default_rnd);
01325 return *this;
01326 }
01327
01328 inline mpreal& mpreal::operator/=(const mpq_t v)
01329 {
01330 mpfr_div_q(mp,mp,v,default_rnd);
01331 return *this;
01332 }
01333
01334 inline mpreal& mpreal::operator/=(const long double v)
01335 {
01336 return *this /= mpreal(v);
01337 }
01338
01339 inline mpreal& mpreal::operator/=(const double v)
01340 {
01341 #if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
01342 mpfr_div_d(mp,mp,v,default_rnd);
01343 return *this;
01344 #else
01345 return *this /= mpreal(v);
01346 #endif
01347 }
01348
01349 inline mpreal& mpreal::operator/=(const unsigned long int v)
01350 {
01351 mpfr_div_ui(mp,mp,v,default_rnd);
01352 return *this;
01353 }
01354
01355 inline mpreal& mpreal::operator/=(const unsigned int v)
01356 {
01357 mpfr_div_ui(mp,mp,v,default_rnd);
01358 return *this;
01359 }
01360
01361 inline mpreal& mpreal::operator/=(const long int v)
01362 {
01363 mpfr_div_si(mp,mp,v,default_rnd);
01364 return *this;
01365 }
01366
01367 inline mpreal& mpreal::operator/=(const int v)
01368 {
01369 mpfr_div_si(mp,mp,v,default_rnd);
01370 return *this;
01371 }
01372
01373 inline const mpreal operator/(const mpreal& a, const mpreal& b)
01374 {
01375 mpreal x(a);
01376 mp_prec_t pb;
01377 mp_prec_t pa;
01378
01379
01380 pa = a.get_prec();
01381 pb = b.get_prec();
01382 if(pb>pa) x.set_prec(pb);
01383
01384 return x /= b;
01385 }
01386
01387 inline const mpreal operator/(const mpreal& a, const mpz_t b)
01388 {
01389 return mpreal(a) /= b;
01390 }
01391
01392 inline const mpreal operator/(const mpreal& a, const mpq_t b)
01393 {
01394 return mpreal(a) /= b;
01395 }
01396
01397 inline const mpreal operator/(const mpreal& a, const long double b)
01398 {
01399 return mpreal(a) /= b;
01400 }
01401
01402 inline const mpreal operator/(const mpreal& a, const double b)
01403 {
01404 return mpreal(a) /= b;
01405 }
01406
01407 inline const mpreal operator/(const mpreal& a, const unsigned long int b)
01408 {
01409 return mpreal(a) /= b;
01410 }
01411
01412 inline const mpreal operator/(const mpreal& a, const unsigned int b)
01413 {
01414 return mpreal(a) /= b;
01415 }
01416
01417 inline const mpreal operator/(const mpreal& a, const long int b)
01418 {
01419 return mpreal(a) /= b;
01420 }
01421
01422 inline const mpreal operator/(const mpreal& a, const int b)
01423 {
01424 return mpreal(a) /= b;
01425 }
01426
01427 inline const mpreal operator/(const unsigned long int b, const mpreal& a)
01428 {
01429 mpreal x(a);
01430 mpfr_ui_div(x.mp,b,a.mp,mpreal::default_rnd);
01431 return x;
01432 }
01433
01434 inline const mpreal operator/(const unsigned int b, const mpreal& a)
01435 {
01436 mpreal x(a);
01437 mpfr_ui_div(x.mp,b,a.mp,mpreal::default_rnd);
01438 return x;
01439 }
01440
01441 inline const mpreal operator/(const long int b, const mpreal& a)
01442 {
01443 mpreal x(a);
01444 mpfr_si_div(x.mp,b,a.mp,mpreal::default_rnd);
01445 return x;
01446 }
01447
01448 inline const mpreal operator/(const int b, const mpreal& a)
01449 {
01450 mpreal x(a);
01451 mpfr_si_div(x.mp,b,a.mp,mpreal::default_rnd);
01452 return x;
01453 }
01454
01455 inline const mpreal operator/(const long double b, const mpreal& a)
01456 {
01457 mpreal x(b);
01458 return x/a;
01459 }
01460
01461 inline const mpreal operator/(const double b, const mpreal& a)
01462 {
01463 #if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
01464 mpreal x(a);
01465 mpfr_d_div(x.mp,b,a.mp,mpreal::default_rnd);
01466 return x;
01467 #else
01468 mpreal x(b);
01469 return x/a;
01470 #endif
01471 }
01472
01474
01475 inline mpreal& mpreal::operator<<=(const unsigned long int u)
01476 {
01477 mpfr_mul_2ui(mp,mp,u,default_rnd);
01478 return *this;
01479 }
01480
01481 inline mpreal& mpreal::operator<<=(const unsigned int u)
01482 {
01483 mpfr_mul_2ui(mp,mp,static_cast<unsigned long int>(u),default_rnd);
01484 return *this;
01485 }
01486
01487 inline mpreal& mpreal::operator<<=(const long int u)
01488 {
01489 mpfr_mul_2si(mp,mp,u,default_rnd);
01490 return *this;
01491 }
01492
01493 inline mpreal& mpreal::operator<<=(const int u)
01494 {
01495 mpfr_mul_2si(mp,mp,static_cast<long int>(u),default_rnd);
01496 return *this;
01497 }
01498
01499 inline mpreal& mpreal::operator>>=(const unsigned long int u)
01500 {
01501 mpfr_div_2ui(mp,mp,u,default_rnd);
01502 return *this;
01503 }
01504
01505 inline mpreal& mpreal::operator>>=(const unsigned int u)
01506 {
01507 mpfr_div_2ui(mp,mp,static_cast<unsigned long int>(u),default_rnd);
01508 return *this;
01509 }
01510
01511 inline mpreal& mpreal::operator>>=(const long int u)
01512 {
01513 mpfr_div_2si(mp,mp,u,default_rnd);
01514 return *this;
01515 }
01516
01517 inline mpreal& mpreal::operator>>=(const int u)
01518 {
01519 mpfr_div_2si(mp,mp,static_cast<long int>(u),default_rnd);
01520 return *this;
01521 }
01522
01523 inline const mpreal operator<<(const mpreal& v, const unsigned long int k)
01524 {
01525 return mul_2ui(v,k);
01526 }
01527
01528 inline const mpreal operator<<(const mpreal& v, const unsigned int k)
01529 {
01530 return mul_2ui(v,static_cast<unsigned long int>(k));
01531 }
01532
01533 inline const mpreal operator<<(const mpreal& v, const long int k)
01534 {
01535 return mul_2si(v,k);
01536 }
01537
01538 inline const mpreal operator<<(const mpreal& v, const int k)
01539 {
01540 return mul_2si(v,static_cast<long int>(k));
01541 }
01542
01543 inline const mpreal operator>>(const mpreal& v, const unsigned long int k)
01544 {
01545 return div_2ui(v,k);
01546 }
01547
01548 inline const mpreal operator>>(const mpreal& v, const long int k)
01549 {
01550 return div_2si(v,k);
01551 }
01552
01553 inline const mpreal operator>>(const mpreal& v, const unsigned int k)
01554 {
01555 return div_2ui(v,static_cast<unsigned long int>(k));
01556 }
01557
01558 inline const mpreal operator>>(const mpreal& v, const int k)
01559 {
01560 return div_2si(v,static_cast<long int>(k));
01561 }
01562
01563
01564 inline const mpreal mul_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode)
01565 {
01566 mpreal x(v);
01567 mpfr_mul_2ui(x.mp,v.mp,k,rnd_mode);
01568 return x;
01569 }
01570
01571
01572 inline const mpreal mul_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode)
01573 {
01574 mpreal x(v);
01575 mpfr_mul_2si(x.mp,v.mp,k,rnd_mode);
01576 return x;
01577 }
01578
01579 inline const mpreal div_2ui(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode)
01580 {
01581 mpreal x(v);
01582 mpfr_div_2ui(x.mp,v.mp,k,rnd_mode);
01583 return x;
01584 }
01585
01586 inline const mpreal div_2si(const mpreal& v, long int k, mp_rnd_t rnd_mode)
01587 {
01588 mpreal x(v);
01589 mpfr_div_2si(x.mp,v.mp,k,rnd_mode);
01590 return x;
01591 }
01592
01594
01595 inline bool operator > (const mpreal& a, const mpreal& b)
01596 {
01597 return (mpfr_greater_p(a.mp,b.mp)!=0);
01598 }
01599
01600 inline bool operator > (const mpreal& a, const unsigned long int b)
01601 {
01602 return a>mpreal(b);
01603 }
01604
01605 inline bool operator > (const mpreal& a, const unsigned int b)
01606 {
01607 return a>mpreal(b);
01608 }
01609
01610 inline bool operator > (const mpreal& a, const long int b)
01611 {
01612 return a>mpreal(b);
01613 }
01614
01615 inline bool operator > (const mpreal& a, const int b)
01616 {
01617 return a>mpreal(b);
01618 }
01619
01620 inline bool operator > (const mpreal& a, const long double b)
01621 {
01622 return a>mpreal(b);
01623 }
01624
01625 inline bool operator > (const mpreal& a, const double b)
01626 {
01627 return a>mpreal(b);
01628 }
01629
01630 inline bool operator > (const unsigned long int a, const mpreal& b)
01631 {
01632 return mpreal(a)>b;
01633 }
01634
01635 inline bool operator > (const unsigned int a, const mpreal& b)
01636 {
01637 return mpreal(a)>b;
01638 }
01639
01640 inline bool operator > (const long int a, const mpreal& b)
01641 {
01642 return mpreal(a)>b;
01643 }
01644
01645 inline bool operator > (const int a, const mpreal& b)
01646 {
01647 return mpreal(a)>b;
01648 }
01649
01650 inline bool operator > (const long double a, const mpreal& b)
01651 {
01652 return mpreal(a)>b;
01653 }
01654
01655 inline bool operator > (const double a, const mpreal& b)
01656 {
01657 return mpreal(a)>b;
01658 }
01659
01660 inline bool operator >= (const mpreal& a, const mpreal& b)
01661 {
01662 return (mpfr_greaterequal_p(a.mp,b.mp)!=0);
01663 }
01664
01665 inline bool operator >= (const mpreal& a, const unsigned long int b)
01666 {
01667 return a>=mpreal(b);
01668 }
01669
01670 inline bool operator >= (const mpreal& a, const unsigned int b)
01671 {
01672 return a>=mpreal(b);
01673 }
01674
01675 inline bool operator >= (const mpreal& a, const long int b)
01676 {
01677 return a>=mpreal(b);
01678 }
01679
01680 inline bool operator >= (const mpreal& a, const int b)
01681 {
01682 return a>=mpreal(b);
01683 }
01684
01685 inline bool operator >= (const mpreal& a, const long double b)
01686 {
01687 return a>=mpreal(b);
01688 }
01689
01690 inline bool operator >= (const mpreal& a, const double b)
01691 {
01692 return a>=mpreal(b);
01693 }
01694
01695 inline bool operator >= (const unsigned long int a,const mpreal& b)
01696 {
01697 return mpreal(a)>=b;
01698 }
01699
01700 inline bool operator >= (const unsigned int a, const mpreal& b)
01701 {
01702 return mpreal(a)>=b;
01703 }
01704
01705 inline bool operator >= (const long int a, const mpreal& b)
01706 {
01707 return mpreal(a)>=b;
01708 }
01709
01710 inline bool operator >= (const int a, const mpreal& b)
01711 {
01712 return mpreal(a)>=b;
01713 }
01714
01715 inline bool operator >= (const long double a, const mpreal& b)
01716 {
01717 return mpreal(a)>=b;
01718 }
01719
01720 inline bool operator >= (const double a, const mpreal& b)
01721 {
01722 return mpreal(a)>=b;
01723 }
01724
01725 inline bool operator < (const mpreal& a, const mpreal& b)
01726 {
01727 return (mpfr_less_p(a.mp,b.mp)!=0);
01728 }
01729
01730 inline bool operator < (const mpreal& a, const unsigned long int b)
01731 {
01732 return a<mpreal(b);
01733 }
01734
01735 inline bool operator < (const mpreal& a, const unsigned int b)
01736 {
01737 return a<mpreal(b);
01738 }
01739
01740 inline bool operator < (const mpreal& a, const long int b)
01741 {
01742 return a<mpreal(b);
01743 }
01744
01745 inline bool operator < (const mpreal& a, const int b)
01746 {
01747 return a<mpreal(b);
01748 }
01749
01750 inline bool operator < (const mpreal& a, const long double b)
01751 {
01752 return a<mpreal(b);
01753 }
01754
01755 inline bool operator < (const mpreal& a, const double b)
01756 {
01757 return a<mpreal(b);
01758 }
01759
01760 inline bool operator < (const unsigned long int a, const mpreal& b)
01761 {
01762 return mpreal(a)<b;
01763 }
01764
01765 inline bool operator < (const unsigned int a,const mpreal& b)
01766 {
01767 return mpreal(a)<b;
01768 }
01769
01770 inline bool operator < (const long int a,const mpreal& b)
01771 {
01772 return mpreal(a)<b;
01773 }
01774
01775 inline bool operator < (const int a,const mpreal& b)
01776 {
01777 return mpreal(a)<b;
01778 }
01779
01780 inline bool operator < (const long double a,const mpreal& b)
01781 {
01782 return mpreal(a)<b;
01783 }
01784
01785 inline bool operator < (const double a,const mpreal& b)
01786 {
01787 return mpreal(a)<b;
01788 }
01789
01790 inline bool operator <= (const mpreal& a, const mpreal& b)
01791 {
01792 return (mpfr_lessequal_p(a.mp,b.mp)!=0);
01793 }
01794
01795 inline bool operator <= (const mpreal& a, const unsigned long int b)
01796 {
01797 return a<=mpreal(b);
01798 }
01799
01800 inline bool operator <= (const mpreal& a, const unsigned int b)
01801 {
01802 return a<=mpreal(b);
01803 }
01804
01805 inline bool operator <= (const mpreal& a, const long int b)
01806 {
01807 return a<=mpreal(b);
01808 }
01809
01810 inline bool operator <= (const mpreal& a, const int b)
01811 {
01812 return a<=mpreal(b);
01813 }
01814
01815 inline bool operator <= (const mpreal& a, const long double b)
01816 {
01817 return a<=mpreal(b);
01818 }
01819
01820 inline bool operator <= (const mpreal& a, const double b)
01821 {
01822 return a<=mpreal(b);
01823 }
01824
01825 inline bool operator <= (const unsigned long int a,const mpreal& b)
01826 {
01827 return mpreal(a)<=b;
01828 }
01829
01830 inline bool operator <= (const unsigned int a, const mpreal& b)
01831 {
01832 return mpreal(a)<=b;
01833 }
01834
01835 inline bool operator <= (const long int a, const mpreal& b)
01836 {
01837 return mpreal(a)<=b;
01838 }
01839
01840 inline bool operator <= (const int a, const mpreal& b)
01841 {
01842 return mpreal(a)<=b;
01843 }
01844
01845 inline bool operator <= (const long double a, const mpreal& b)
01846 {
01847 return mpreal(a)<=b;
01848 }
01849
01850 inline bool operator <= (const double a, const mpreal& b)
01851 {
01852 return mpreal(a)<=b;
01853 }
01854
01855 inline bool operator == (const mpreal& a, const mpreal& b)
01856 {
01857 return (mpfr_equal_p(a.mp,b.mp)!=0);
01858 }
01859
01860 inline bool operator == (const mpreal& a, const unsigned long int b)
01861 {
01862 return a==mpreal(b);
01863 }
01864
01865 inline bool operator == (const mpreal& a, const unsigned int b)
01866 {
01867 return a==mpreal(b);
01868 }
01869
01870 inline bool operator == (const mpreal& a, const long int b)
01871 {
01872 return a==mpreal(b);
01873 }
01874
01875 inline bool operator == (const mpreal& a, const int b)
01876 {
01877 return a==mpreal(b);
01878 }
01879
01880 inline bool operator == (const mpreal& a, const long double b)
01881 {
01882 return a==mpreal(b);
01883 }
01884
01885 inline bool operator == (const mpreal& a, const double b)
01886 {
01887 return a==mpreal(b);
01888 }
01889
01890 inline bool operator == (const unsigned long int a,const mpreal& b)
01891 {
01892 return mpreal(a)==b;
01893 }
01894
01895 inline bool operator == (const unsigned int a, const mpreal& b)
01896 {
01897 return mpreal(a)==b;
01898 }
01899
01900 inline bool operator == (const long int a, const mpreal& b)
01901 {
01902 return mpreal(a)==b;
01903 }
01904
01905 inline bool operator == (const int a, const mpreal& b)
01906 {
01907 return mpreal(a)==b;
01908 }
01909
01910 inline bool operator == (const long double a, const mpreal& b)
01911 {
01912 return mpreal(a)==b;
01913 }
01914
01915 inline bool operator == (const double a, const mpreal& b)
01916 {
01917 return mpreal(a)==b;
01918 }
01919
01920 inline bool operator != (const mpreal& a, const mpreal& b)
01921 {
01922 return (mpfr_lessgreater_p(a.mp,b.mp)!=0);
01923 }
01924
01925 inline bool operator != (const mpreal& a, const unsigned long int b)
01926 {
01927 return a!=mpreal(b);
01928 }
01929
01930 inline bool operator != (const mpreal& a, const unsigned int b)
01931 {
01932 return a!=mpreal(b);
01933 }
01934
01935 inline bool operator != (const mpreal& a, const long int b)
01936 {
01937 return a!=mpreal(b);
01938 }
01939
01940 inline bool operator != (const mpreal& a, const int b)
01941 {
01942 return a!=mpreal(b);
01943 }
01944
01945 inline bool operator != (const mpreal& a, const long double b)
01946 {
01947 return a!=mpreal(b);
01948 }
01949
01950 inline bool operator != (const mpreal& a, const double b)
01951 {
01952 return a!=mpreal(b);
01953 }
01954
01955 inline bool operator != (const unsigned long int a,const mpreal& b)
01956 {
01957 return mpreal(a)!=b;
01958 }
01959
01960 inline bool operator != (const unsigned int a, const mpreal& b)
01961 {
01962 return mpreal(a)!=b;
01963 }
01964
01965 inline bool operator != (const long int a, const mpreal& b)
01966 {
01967 return mpreal(a)!=b;
01968 }
01969
01970 inline bool operator != (const int a, const mpreal& b)
01971 {
01972 return mpreal(a)!=b;
01973 }
01974
01975 inline bool operator != (const long double a, const mpreal& b)
01976 {
01977 return mpreal(a)!=b;
01978 }
01979
01980 inline bool operator != (const double a, const mpreal& b)
01981 {
01982 return mpreal(a)!=b;
01983 }
01984
01985 inline bool _isnan(const mpreal& v)
01986 {
01987 return (mpfr_nan_p(v.mp)!=0);
01988 }
01989
01990 inline bool _isinf(const mpreal& v)
01991 {
01992 return (mpfr_inf_p(v.mp)!=0);
01993 }
01994
01995 inline bool _isnum(const mpreal& v)
01996 {
01997 return (mpfr_number_p(v.mp)!=0);
01998 }
01999
02000 inline bool _iszero(const mpreal& v)
02001 {
02002 return (mpfr_zero_p(v.mp)!=0);
02003 }
02004
02005 inline bool _isint(const mpreal& v)
02006 {
02007 return (mpfr_integer_p(v.mp)!=0);
02008 }
02009
02010 #if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
02011 inline bool _isregular(const mpreal& v)
02012 {
02013 return (mpfr_regular_p(v.mp));
02014 }
02015 #endif // MPFR 3.0.0 Specifics
02016
02018
02019 inline mpreal::operator double() const
02020 {
02021 return mpfr_get_d(mp,default_rnd);
02022 }
02023
02024 inline mpreal::operator float() const
02025 {
02026 return (float)mpfr_get_d(mp,default_rnd);
02027 }
02028
02029 inline mpreal::operator long double() const
02030 {
02031 return mpfr_get_ld(mp,default_rnd);
02032 }
02033
02034 inline mpreal::operator unsigned long() const
02035 {
02036 return mpfr_get_ui(mp,GMP_RNDZ);
02037 }
02038
02039 inline mpreal::operator unsigned int() const
02040 {
02041 return static_cast<unsigned int>(mpfr_get_ui(mp,GMP_RNDZ));
02042 }
02043
02044 inline mpreal::operator long() const
02045 {
02046 return mpfr_get_si(mp,GMP_RNDZ);
02047 }
02048
02049 inline mpreal::operator int() const
02050 {
02051 return static_cast<int>(mpfr_get_si(mp,GMP_RNDZ));
02052 }
02053
02054 inline mpreal::operator mpfr_ptr()
02055 {
02056 return mp;
02057 }
02058
02060
02061 inline int sgn(const mpreal& v)
02062 {
02063 int r = mpfr_signbit(v.mp);
02064 return (r>0?-1:1);
02065 }
02066
02067 inline void mpreal::set_sign(int sign, mp_rnd_t rnd_mode)
02068 {
02069 mpfr_setsign(mp,mp,(sign<0?1:0),rnd_mode);
02070 }
02071
02072 inline mp_prec_t mpreal::get_prec() const
02073 {
02074 return mpfr_get_prec(mp);
02075 }
02076
02077 inline void mpreal::set_prec(mp_prec_t prec, mp_rnd_t rnd_mode)
02078 {
02079 mpfr_prec_round(mp,prec,rnd_mode);
02080 }
02081
02082 inline void mpreal::set_inf(int sign)
02083 {
02084 mpfr_set_inf(mp,sign);
02085 }
02086
02087 inline void mpreal::set_nan()
02088 {
02089 mpfr_set_nan(mp);
02090 }
02091
02092 inline mp_exp_t mpreal::get_exp ()
02093 {
02094 return mpfr_get_exp(mp);
02095 }
02096
02097 inline int mpreal::set_exp (mp_exp_t e)
02098 {
02099 return mpfr_set_exp(mp,e);
02100 }
02101
02102 inline const mpreal frexp(const mpreal& v, mp_exp_t* exp)
02103 {
02104 mpreal x(v);
02105 *exp = x.get_exp();
02106 x.set_exp(0);
02107 return x;
02108 }
02109
02110 inline const mpreal ldexp(const mpreal& v, mp_exp_t exp)
02111 {
02112 mpreal x(v);
02113
02114
02115 mpfr_mul_2si(x.mp,x.mp,exp,mpreal::default_rnd);
02116 return x;
02117 }
02118
02119 inline const mpreal machine_epsilon(mp_prec_t prec)
02120 {
02121
02122
02123 mpreal x(1,prec);
02124 return nextabove(x)-x;
02125 }
02126
02127 inline const mpreal mpreal_min(mp_prec_t prec)
02128 {
02129
02130
02131 mpreal x(1,prec);
02132 return x <<= mpreal::get_emin()-1;
02133 }
02134
02135 inline const mpreal mpreal_max(mp_prec_t prec)
02136 {
02137
02138
02139
02140
02141 mpreal x(1,prec);
02142 return x <<= mpreal::get_emax()-1;
02143 }
02144
02145 inline const mpreal modf(const mpreal& v, mpreal& n)
02146 {
02147 mpreal frac(v);
02148
02149
02150 mpfr_frac(frac.mp,frac.mp,mpreal::default_rnd);
02151 mpfr_trunc(n.mp,v.mp);
02152 return frac;
02153 }
02154
02155 inline int mpreal::check_range (int t, mp_rnd_t rnd_mode)
02156 {
02157 return mpfr_check_range(mp,t,rnd_mode);
02158 }
02159
02160 inline int mpreal::subnormalize (int t,mp_rnd_t rnd_mode)
02161 {
02162 return mpfr_subnormalize(mp,t,rnd_mode);
02163 }
02164
02165 inline mp_exp_t mpreal::get_emin (void)
02166 {
02167 return mpfr_get_emin();
02168 }
02169
02170 inline int mpreal::set_emin (mp_exp_t exp)
02171 {
02172 return mpfr_set_emin(exp);
02173 }
02174
02175 inline mp_exp_t mpreal::get_emax (void)
02176 {
02177 return mpfr_get_emax();
02178 }
02179
02180 inline int mpreal::set_emax (mp_exp_t exp)
02181 {
02182 return mpfr_set_emax(exp);
02183 }
02184
02185 inline mp_exp_t mpreal::get_emin_min (void)
02186 {
02187 return mpfr_get_emin_min();
02188 }
02189
02190 inline mp_exp_t mpreal::get_emin_max (void)
02191 {
02192 return mpfr_get_emin_max();
02193 }
02194
02195 inline mp_exp_t mpreal::get_emax_min (void)
02196 {
02197 return mpfr_get_emax_min();
02198 }
02199
02200 inline mp_exp_t mpreal::get_emax_max (void)
02201 {
02202 return mpfr_get_emax_max();
02203 }
02204
02206
02208 inline const mpreal sqr(const mpreal& v, mp_rnd_t rnd_mode)
02209 {
02210 mpreal x(v);
02211 mpfr_sqr(x.mp,x.mp,rnd_mode);
02212 return x;
02213 }
02214
02215 inline const mpreal sqrt(const mpreal& v, mp_rnd_t rnd_mode)
02216 {
02217 mpreal x(v);
02218 mpfr_sqrt(x.mp,x.mp,rnd_mode);
02219 return x;
02220 }
02221
02222 inline const mpreal sqrt(const unsigned long int v, mp_rnd_t rnd_mode)
02223 {
02224 mpreal x;
02225 mpfr_sqrt_ui(x.mp,v,rnd_mode);
02226 return x;
02227 }
02228
02229 inline const mpreal sqrt(const unsigned int v, mp_rnd_t rnd_mode)
02230 {
02231 return sqrt(static_cast<unsigned long int>(v),rnd_mode);
02232 }
02233
02234 inline const mpreal sqrt(const long int v, mp_rnd_t rnd_mode)
02235 {
02236 if (v>=0) return sqrt(static_cast<unsigned long int>(v),rnd_mode);
02237 else return mpreal();
02238 }
02239
02240 inline const mpreal sqrt(const int v, mp_rnd_t rnd_mode)
02241 {
02242 if (v>=0) return sqrt(static_cast<unsigned long int>(v),rnd_mode);
02243 else return mpreal();
02244 }
02245
02246 inline const mpreal sqrt(const long double v, mp_rnd_t rnd_mode)
02247 {
02248 return sqrt(mpreal(v),rnd_mode);
02249 }
02250
02251 inline const mpreal sqrt(const double v, mp_rnd_t rnd_mode)
02252 {
02253 return sqrt(mpreal(v),rnd_mode);
02254 }
02255
02256 inline const mpreal cbrt(const mpreal& v, mp_rnd_t rnd_mode)
02257 {
02258 mpreal x(v);
02259 mpfr_cbrt(x.mp,x.mp,rnd_mode);
02260 return x;
02261 }
02262
02263 inline const mpreal root(const mpreal& v, unsigned long int k, mp_rnd_t rnd_mode)
02264 {
02265 mpreal x(v);
02266 mpfr_root(x.mp,x.mp,k,rnd_mode);
02267 return x;
02268 }
02269
02270 inline const mpreal fabs(const mpreal& v, mp_rnd_t rnd_mode)
02271 {
02272 mpreal x(v);
02273 mpfr_abs(x.mp,x.mp,rnd_mode);
02274 return x;
02275 }
02276
02277 inline const mpreal abs(const mpreal& v, mp_rnd_t rnd_mode)
02278 {
02279 mpreal x(v);
02280 mpfr_abs(x.mp,x.mp,rnd_mode);
02281 return x;
02282 }
02283
02284 inline const mpreal dim(const mpreal& a, const mpreal& b, mp_rnd_t rnd_mode)
02285 {
02286 mpreal x(a);
02287 mpfr_dim(x.mp,a.mp,b.mp,rnd_mode);
02288 return x;
02289 }
02290
02291 inline int cmpabs(const mpreal& a,const mpreal& b)
02292 {
02293 return mpfr_cmpabs(a.mp,b.mp);
02294 }
02295
02296 inline const mpreal log (const mpreal& v, mp_rnd_t rnd_mode)
02297 {
02298 mpreal x(v);
02299 mpfr_log(x.mp,v.mp,rnd_mode);
02300 return x;
02301 }
02302
02303 inline const mpreal log2(const mpreal& v, mp_rnd_t rnd_mode)
02304 {
02305 mpreal x(v);
02306 mpfr_log2(x.mp,v.mp,rnd_mode);
02307 return x;
02308 }
02309
02310 inline const mpreal log10(const mpreal& v, mp_rnd_t rnd_mode)
02311 {
02312 mpreal x(v);
02313 mpfr_log10(x.mp,v.mp,rnd_mode);
02314 return x;
02315 }
02316
02317 inline const mpreal exp(const mpreal& v, mp_rnd_t rnd_mode)
02318 {
02319 mpreal x(v);
02320 mpfr_exp(x.mp,v.mp,rnd_mode);
02321 return x;
02322 }
02323
02324 inline const mpreal exp2(const mpreal& v, mp_rnd_t rnd_mode)
02325 {
02326 mpreal x(v);
02327 mpfr_exp2(x.mp,v.mp,rnd_mode);
02328 return x;
02329 }
02330
02331 inline const mpreal exp10(const mpreal& v, mp_rnd_t rnd_mode)
02332 {
02333 mpreal x(v);
02334 mpfr_exp10(x.mp,v.mp,rnd_mode);
02335 return x;
02336 }
02337
02338 inline const mpreal cos(const mpreal& v, mp_rnd_t rnd_mode)
02339 {
02340 mpreal x(v);
02341 mpfr_cos(x.mp,v.mp,rnd_mode);
02342 return x;
02343 }
02344
02345 inline const mpreal sin(const mpreal& v, mp_rnd_t rnd_mode)
02346 {
02347 mpreal x(v);
02348 mpfr_sin(x.mp,v.mp,rnd_mode);
02349 return x;
02350 }
02351
02352 inline const mpreal tan(const mpreal& v, mp_rnd_t rnd_mode)
02353 {
02354 mpreal x(v);
02355 mpfr_tan(x.mp,v.mp,rnd_mode);
02356 return x;
02357 }
02358
02359 inline const mpreal sec(const mpreal& v, mp_rnd_t rnd_mode)
02360 {
02361 mpreal x(v);
02362 mpfr_sec(x.mp,v.mp,rnd_mode);
02363 return x;
02364 }
02365
02366 inline const mpreal csc(const mpreal& v, mp_rnd_t rnd_mode)
02367 {
02368 mpreal x(v);
02369 mpfr_csc(x.mp,v.mp,rnd_mode);
02370 return x;
02371 }
02372
02373 inline const mpreal cot(const mpreal& v, mp_rnd_t rnd_mode)
02374 {
02375 mpreal x(v);
02376 mpfr_cot(x.mp,v.mp,rnd_mode);
02377 return x;
02378 }
02379
02380 inline int sin_cos(mpreal& s, mpreal& c, const mpreal& v, mp_rnd_t rnd_mode)
02381 {
02382 return mpfr_sin_cos(s.mp,c.mp,v.mp,rnd_mode);
02383 }
02384
02385 inline const mpreal acos (const mpreal& v, mp_rnd_t rnd_mode)
02386 {
02387 mpreal x(v);
02388 mpfr_acos(x.mp,v.mp,rnd_mode);
02389 return x;
02390 }
02391
02392 inline const mpreal asin (const mpreal& v, mp_rnd_t rnd_mode)
02393 {
02394 mpreal x(v);
02395 mpfr_asin(x.mp,v.mp,rnd_mode);
02396 return x;
02397 }
02398
02399 inline const mpreal atan (const mpreal& v, mp_rnd_t rnd_mode)
02400 {
02401 mpreal x(v);
02402 mpfr_atan(x.mp,v.mp,rnd_mode);
02403 return x;
02404 }
02405
02406 inline const mpreal atan2 (const mpreal& y, const mpreal& x, mp_rnd_t rnd_mode)
02407 {
02408 mpreal a;
02409 mp_prec_t yp, xp;
02410
02411 yp = y.get_prec();
02412 xp = x.get_prec();
02413
02414 a.set_prec(yp>xp?yp:xp);
02415
02416 mpfr_atan2(a.mp, y.mp, x.mp, rnd_mode);
02417
02418 return a;
02419 }
02420
02421 inline const mpreal cosh (const mpreal& v, mp_rnd_t rnd_mode)
02422 {
02423 mpreal x(v);
02424 mpfr_cosh(x.mp,v.mp,rnd_mode);
02425 return x;
02426 }
02427
02428 inline const mpreal sinh (const mpreal& v, mp_rnd_t rnd_mode)
02429 {
02430 mpreal x(v);
02431 mpfr_sinh(x.mp,v.mp,rnd_mode);
02432 return x;
02433 }
02434
02435 inline const mpreal tanh (const mpreal& v, mp_rnd_t rnd_mode)
02436 {
02437 mpreal x(v);
02438 mpfr_tanh(x.mp,v.mp,rnd_mode);
02439 return x;
02440 }
02441
02442 inline const mpreal sech (const mpreal& v, mp_rnd_t rnd_mode)
02443 {
02444 mpreal x(v);
02445 mpfr_sech(x.mp,v.mp,rnd_mode);
02446 return x;
02447 }
02448
02449 inline const mpreal csch (const mpreal& v, mp_rnd_t rnd_mode)
02450 {
02451 mpreal x(v);
02452 mpfr_csch(x.mp,v.mp,rnd_mode);
02453 return x;
02454 }
02455
02456 inline const mpreal coth (const mpreal& v, mp_rnd_t rnd_mode)
02457 {
02458 mpreal x(v);
02459 mpfr_coth(x.mp,v.mp,rnd_mode);
02460 return x;
02461 }
02462
02463 inline const mpreal acosh (const mpreal& v, mp_rnd_t rnd_mode)
02464 {
02465 mpreal x(v);
02466 mpfr_acosh(x.mp,v.mp,rnd_mode);
02467 return x;
02468 }
02469
02470 inline const mpreal asinh (const mpreal& v, mp_rnd_t rnd_mode)
02471 {
02472 mpreal x(v);
02473 mpfr_asinh(x.mp,v.mp,rnd_mode);
02474 return x;
02475 }
02476
02477 inline const mpreal atanh (const mpreal& v, mp_rnd_t rnd_mode)
02478 {
02479 mpreal x(v);
02480 mpfr_atanh(x.mp,v.mp,rnd_mode);
02481 return x;
02482 }
02483
02484 inline const mpreal fac_ui (unsigned long int v, mp_prec_t prec, mp_rnd_t rnd_mode)
02485 {
02486 mpreal x(0,prec);
02487 mpfr_fac_ui(x.mp,v,rnd_mode);
02488 return x;
02489 }
02490
02491 inline const mpreal log1p (const mpreal& v, mp_rnd_t rnd_mode)
02492 {
02493 mpreal x(v);
02494 mpfr_log1p(x.mp,v.mp,rnd_mode);
02495 return x;
02496 }
02497
02498 inline const mpreal expm1 (const mpreal& v, mp_rnd_t rnd_mode)
02499 {
02500 mpreal x(v);
02501 mpfr_expm1(x.mp,v.mp,rnd_mode);
02502 return x;
02503 }
02504
02505 inline const mpreal eint (const mpreal& v, mp_rnd_t rnd_mode)
02506 {
02507 mpreal x(v);
02508 mpfr_eint(x.mp,v.mp,rnd_mode);
02509 return x;
02510 }
02511
02512 inline const mpreal gamma (const mpreal& v, mp_rnd_t rnd_mode)
02513 {
02514 mpreal x(v);
02515 mpfr_gamma(x.mp,v.mp,rnd_mode);
02516 return x;
02517 }
02518
02519 inline const mpreal lngamma (const mpreal& v, mp_rnd_t rnd_mode)
02520 {
02521 mpreal x(v);
02522 mpfr_lngamma(x.mp,v.mp,rnd_mode);
02523 return x;
02524 }
02525
02526 inline const mpreal lgamma (const mpreal& v, int *signp, mp_rnd_t rnd_mode)
02527 {
02528 mpreal x(v);
02529 int tsignp;
02530
02531 if(signp)
02532 mpfr_lgamma(x.mp,signp,v.mp,rnd_mode);
02533 else
02534 mpfr_lgamma(x.mp,&tsignp,v.mp,rnd_mode);
02535
02536 return x;
02537 }
02538
02539 inline const mpreal zeta (const mpreal& v, mp_rnd_t rnd_mode)
02540 {
02541 mpreal x(v);
02542 mpfr_zeta(x.mp,v.mp,rnd_mode);
02543 return x;
02544 }
02545
02546 inline const mpreal erf (const mpreal& v, mp_rnd_t rnd_mode)
02547 {
02548 mpreal x(v);
02549 mpfr_erf(x.mp,v.mp,rnd_mode);
02550 return x;
02551 }
02552
02553 inline const mpreal erfc (const mpreal& v, mp_rnd_t rnd_mode)
02554 {
02555 mpreal x(v);
02556 mpfr_erfc(x.mp,v.mp,rnd_mode);
02557 return x;
02558 }
02559
02560 inline const mpreal _j0 (const mpreal& v, mp_rnd_t rnd_mode)
02561 {
02562 mpreal x(v);
02563 mpfr_j0(x.mp,v.mp,rnd_mode);
02564 return x;
02565 }
02566
02567 inline const mpreal _j1 (const mpreal& v, mp_rnd_t rnd_mode)
02568 {
02569 mpreal x(v);
02570 mpfr_j1(x.mp,v.mp,rnd_mode);
02571 return x;
02572 }
02573
02574 inline const mpreal _jn (long n, const mpreal& v, mp_rnd_t rnd_mode)
02575 {
02576 mpreal x(v);
02577 mpfr_jn(x.mp,n,v.mp,rnd_mode);
02578 return x;
02579 }
02580
02581 inline const mpreal _y0 (const mpreal& v, mp_rnd_t rnd_mode)
02582 {
02583 mpreal x(v);
02584 mpfr_y0(x.mp,v.mp,rnd_mode);
02585 return x;
02586 }
02587
02588 inline const mpreal _y1 (const mpreal& v, mp_rnd_t rnd_mode)
02589 {
02590 mpreal x(v);
02591 mpfr_y1(x.mp,v.mp,rnd_mode);
02592 return x;
02593 }
02594
02595 inline const mpreal _yn (long n, const mpreal& v, mp_rnd_t rnd_mode)
02596 {
02597 mpreal x(v);
02598 mpfr_yn(x.mp,n,v.mp,rnd_mode);
02599 return x;
02600 }
02601
02603
02604 #if (MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0))
02605
02606 inline int sinh_cosh(mpreal& s, mpreal& c, const mpreal& v, mp_rnd_t rnd_mode)
02607 {
02608 return mpfr_sinh_cosh(s.mp,c.mp,v.mp,rnd_mode);
02609 }
02610
02611 inline const mpreal li2(const mpreal& v, mp_rnd_t rnd_mode)
02612 {
02613 mpreal x(v);
02614 mpfr_li2(x.mp,v.mp,rnd_mode);
02615 return x;
02616 }
02617
02618 inline const mpreal fmod (const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode)
02619 {
02620 mpreal a;
02621 mp_prec_t yp, xp;
02622
02623 yp = y.get_prec();
02624 xp = x.get_prec();
02625
02626 a.set_prec(yp>xp?yp:xp);
02627
02628 mpfr_fmod(a.mp, x.mp, y.mp, rnd_mode);
02629
02630 return a;
02631 }
02632
02633 inline const mpreal rec_sqrt(const mpreal& v, mp_rnd_t rnd_mode)
02634 {
02635 mpreal x(v);
02636 mpfr_rec_sqrt(x.mp,v.mp,rnd_mode);
02637 return x;
02638 }
02639 #endif // MPFR 2.4.0 Specifics
02640
02642
02643 #if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
02644
02645 inline const mpreal digamma(const mpreal& v, mp_rnd_t rnd_mode)
02646 {
02647 mpreal x(v);
02648 mpfr_digamma(x.mp,v.mp,rnd_mode);
02649 return x;
02650 }
02651
02652 inline const mpreal ai(const mpreal& v, mp_rnd_t rnd_mode)
02653 {
02654 mpreal x(v);
02655 mpfr_ai(x.mp,v.mp,rnd_mode);
02656 return x;
02657 }
02658
02659 #endif // MPFR 3.0.0 Specifics
02660
02662
02663 inline const mpreal const_log2 (mp_prec_t prec, mp_rnd_t rnd_mode)
02664 {
02665 mpreal x;
02666 x.set_prec(prec);
02667 mpfr_const_log2(x.mp,rnd_mode);
02668 return x;
02669 }
02670
02671 inline const mpreal const_pi (mp_prec_t prec, mp_rnd_t rnd_mode)
02672 {
02673 mpreal x;
02674 x.set_prec(prec);
02675 mpfr_const_pi(x.mp,rnd_mode);
02676 return x;
02677 }
02678
02679 inline const mpreal const_euler (mp_prec_t prec, mp_rnd_t rnd_mode)
02680 {
02681 mpreal x;
02682 x.set_prec(prec);
02683 mpfr_const_euler(x.mp,rnd_mode);
02684 return x;
02685 }
02686
02687 inline const mpreal const_catalan (mp_prec_t prec, mp_rnd_t rnd_mode)
02688 {
02689 mpreal x;
02690 x.set_prec(prec);
02691 mpfr_const_catalan(x.mp,rnd_mode);
02692 return x;
02693 }
02694
02695 inline const mpreal const_infinity (int sign, mp_prec_t prec, mp_rnd_t rnd_mode)
02696 {
02697 mpreal x;
02698 x.set_prec(prec,rnd_mode);
02699 mpfr_set_inf(x.mp, sign);
02700 return x;
02701 }
02702
02704
02705 inline const mpreal rint(const mpreal& v, mp_rnd_t rnd_mode)
02706 {
02707 mpreal x(v);
02708 mpfr_rint(x.mp,v.mp,rnd_mode);
02709 return x;
02710 }
02711
02712 inline const mpreal ceil(const mpreal& v)
02713 {
02714 mpreal x(v);
02715 mpfr_ceil(x.mp,v.mp);
02716 return x;
02717
02718 }
02719
02720 inline const mpreal floor(const mpreal& v)
02721 {
02722 mpreal x(v);
02723 mpfr_floor(x.mp,v.mp);
02724 return x;
02725 }
02726
02727 inline const mpreal round(const mpreal& v)
02728 {
02729 mpreal x(v);
02730 mpfr_round(x.mp,v.mp);
02731 return x;
02732 }
02733
02734 inline const mpreal trunc(const mpreal& v)
02735 {
02736 mpreal x(v);
02737 mpfr_trunc(x.mp,v.mp);
02738 return x;
02739 }
02740
02741 inline const mpreal rint_ceil (const mpreal& v, mp_rnd_t rnd_mode)
02742 {
02743 mpreal x(v);
02744 mpfr_rint_ceil(x.mp,v.mp,rnd_mode);
02745 return x;
02746 }
02747
02748 inline const mpreal rint_floor(const mpreal& v, mp_rnd_t rnd_mode)
02749 {
02750 mpreal x(v);
02751 mpfr_rint_floor(x.mp,v.mp,rnd_mode);
02752 return x;
02753 }
02754
02755 inline const mpreal rint_round(const mpreal& v, mp_rnd_t rnd_mode)
02756 {
02757 mpreal x(v);
02758 mpfr_rint_round(x.mp,v.mp,rnd_mode);
02759 return x;
02760 }
02761
02762 inline const mpreal rint_trunc(const mpreal& v, mp_rnd_t rnd_mode)
02763 {
02764 mpreal x(v);
02765 mpfr_rint_trunc(x.mp,v.mp,rnd_mode);
02766 return x;
02767 }
02768
02769 inline const mpreal frac (const mpreal& v, mp_rnd_t rnd_mode)
02770 {
02771 mpreal x(v);
02772 mpfr_frac(x.mp,v.mp,rnd_mode);
02773 return x;
02774 }
02775
02777
02778 inline void swap(mpreal& a, mpreal& b)
02779 {
02780 mpfr_swap(a.mp,b.mp);
02781 }
02782
02783
02784 inline const mpreal (max)(const mpreal& x, const mpreal& y)
02785 {
02786 return (x>y?x:y);
02787 }
02788
02789 inline const mpreal (min)(const mpreal& x, const mpreal& y)
02790 {
02791 return (x<y?x:y);
02792 }
02793
02794 inline const mpreal fmax(const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode)
02795 {
02796 mpreal a;
02797 mpfr_max(a.mp,x.mp,y.mp,rnd_mode);
02798 return a;
02799 }
02800
02801 inline const mpreal fmin(const mpreal& x, const mpreal& y, mp_rnd_t rnd_mode)
02802 {
02803 mpreal a;
02804 mpfr_min(a.mp,x.mp,y.mp,rnd_mode);
02805 return a;
02806 }
02807
02808 inline const mpreal nexttoward (const mpreal& x, const mpreal& y)
02809 {
02810 mpreal a(x);
02811 mpfr_nexttoward(a.mp,y.mp);
02812 return a;
02813 }
02814
02815 inline const mpreal nextabove (const mpreal& x)
02816 {
02817 mpreal a(x);
02818 mpfr_nextabove(a.mp);
02819 return a;
02820 }
02821
02822 inline const mpreal nextbelow (const mpreal& x)
02823 {
02824 mpreal a(x);
02825 mpfr_nextbelow(a.mp);
02826 return a;
02827 }
02828
02829 inline const mpreal urandomb (gmp_randstate_t& state)
02830 {
02831 mpreal x;
02832 mpfr_urandomb(x.mp,state);
02833 return x;
02834 }
02835
02836 #if (MPFR_VERSION >= MPFR_VERSION_NUM(3,0,0))
02837
02838 inline const mpreal urandom (gmp_randstate_t& state,mp_rnd_t rnd_mode)
02839 {
02840 mpreal x;
02841 mpfr_urandom(x.mp,state,rnd_mode);
02842 return x;
02843 }
02844 #endif
02845
02846 #if (MPFR_VERSION <= MPFR_VERSION_NUM(2,4,2))
02847 inline const mpreal random2 (mp_size_t size, mp_exp_t exp)
02848 {
02849 mpreal x;
02850 mpfr_random2(x.mp,size,exp);
02851 return x;
02852 }
02853 #endif
02854
02856
02857 inline void mpreal::set_default_prec(mp_prec_t prec)
02858 {
02859 default_prec = prec;
02860 mpfr_set_default_prec(prec);
02861 }
02862
02863 inline mp_prec_t mpreal::get_default_prec()
02864 {
02865 return mpfr_get_default_prec();
02866 }
02867
02868 inline void mpreal::set_default_base(int base)
02869 {
02870 default_base = base;
02871 }
02872
02873 inline int mpreal::get_default_base()
02874 {
02875 return default_base;
02876 }
02877
02878 inline void mpreal::set_default_rnd(mp_rnd_t rnd_mode)
02879 {
02880 default_rnd = rnd_mode;
02881 mpfr_set_default_rounding_mode(rnd_mode);
02882 }
02883
02884 inline mp_rnd_t mpreal::get_default_rnd()
02885 {
02886 return mpfr_get_default_rounding_mode();
02887 }
02888
02889 inline void mpreal::set_double_bits(int dbits)
02890 {
02891 double_bits = dbits;
02892 }
02893
02894 inline int mpreal::get_double_bits()
02895 {
02896 return double_bits;
02897 }
02898
02899 inline bool mpreal::fits_in_bits(double x, int n)
02900 {
02901 int i;
02902 double t;
02903 return IsInf(x) || (std::modf ( std::ldexp ( std::frexp ( x, &i ), n ), &t ) == 0.0);
02904 }
02905
02906 inline const mpreal pow(const mpreal& a, const mpreal& b, mp_rnd_t rnd_mode)
02907 {
02908 mpreal x(a);
02909 mpfr_pow(x.mp,x.mp,b.mp,rnd_mode);
02910 return x;
02911 }
02912
02913 inline const mpreal pow(const mpreal& a, const mpz_t b, mp_rnd_t rnd_mode)
02914 {
02915 mpreal x(a);
02916 mpfr_pow_z(x.mp,x.mp,b,rnd_mode);
02917 return x;
02918 }
02919
02920 inline const mpreal pow(const mpreal& a, const unsigned long int b, mp_rnd_t rnd_mode)
02921 {
02922 mpreal x(a);
02923 mpfr_pow_ui(x.mp,x.mp,b,rnd_mode);
02924 return x;
02925 }
02926
02927 inline const mpreal pow(const mpreal& a, const unsigned int b, mp_rnd_t rnd_mode)
02928 {
02929 return pow(a,static_cast<unsigned long int>(b),rnd_mode);
02930 }
02931
02932 inline const mpreal pow(const mpreal& a, const long int b, mp_rnd_t rnd_mode)
02933 {
02934 mpreal x(a);
02935 mpfr_pow_si(x.mp,x.mp,b,rnd_mode);
02936 return x;
02937 }
02938
02939 inline const mpreal pow(const mpreal& a, const int b, mp_rnd_t rnd_mode)
02940 {
02941 return pow(a,static_cast<long int>(b),rnd_mode);
02942 }
02943
02944 inline const mpreal pow(const mpreal& a, const long double b, mp_rnd_t rnd_mode)
02945 {
02946 return pow(a,mpreal(b),rnd_mode);
02947 }
02948
02949 inline const mpreal pow(const mpreal& a, const double b, mp_rnd_t rnd_mode)
02950 {
02951 return pow(a,mpreal(b),rnd_mode);
02952 }
02953
02954 inline const mpreal pow(const unsigned long int a, const mpreal& b, mp_rnd_t rnd_mode)
02955 {
02956 mpreal x(a);
02957 mpfr_ui_pow(x.mp,a,b.mp,rnd_mode);
02958 return x;
02959 }
02960
02961 inline const mpreal pow(const unsigned int a, const mpreal& b, mp_rnd_t rnd_mode)
02962 {
02963 return pow(static_cast<unsigned long int>(a),b,rnd_mode);
02964 }
02965
02966 inline const mpreal pow(const long int a, const mpreal& b, mp_rnd_t rnd_mode)
02967 {
02968 if (a>=0) return pow(static_cast<unsigned long int>(a),b,rnd_mode);
02969 else return pow(mpreal(a),b,rnd_mode);
02970 }
02971
02972 inline const mpreal pow(const int a, const mpreal& b, mp_rnd_t rnd_mode)
02973 {
02974 if (a>=0) return pow(static_cast<unsigned long int>(a),b,rnd_mode);
02975 else return pow(mpreal(a),b,rnd_mode);
02976 }
02977
02978 inline const mpreal pow(const long double a, const mpreal& b, mp_rnd_t rnd_mode)
02979 {
02980 return pow(mpreal(a),b,rnd_mode);
02981 }
02982
02983 inline const mpreal pow(const double a, const mpreal& b, mp_rnd_t rnd_mode)
02984 {
02985 return pow(mpreal(a),b,rnd_mode);
02986 }
02987
02988
02989 inline const mpreal pow(const unsigned long int a, const unsigned long int b, mp_rnd_t rnd_mode)
02990 {
02991 mpreal x(a);
02992 mpfr_ui_pow_ui(x.mp,a,b,rnd_mode);
02993 return x;
02994 }
02995
02996 inline const mpreal pow(const unsigned long int a, const unsigned int b, mp_rnd_t rnd_mode)
02997 {
02998 return pow(a,static_cast<unsigned long int>(b),rnd_mode);
02999 }
03000
03001 inline const mpreal pow(const unsigned long int a, const long int b, mp_rnd_t rnd_mode)
03002 {
03003 if(b>0) return pow(a,static_cast<unsigned long int>(b),rnd_mode);
03004 else return pow(a,mpreal(b),rnd_mode);
03005 }
03006
03007 inline const mpreal pow(const unsigned long int a, const int b, mp_rnd_t rnd_mode)
03008 {
03009 if(b>0) return pow(a,static_cast<unsigned long int>(b),rnd_mode);
03010 else return pow(a,mpreal(b),rnd_mode);
03011 }
03012
03013 inline const mpreal pow(const unsigned long int a, const long double b, mp_rnd_t rnd_mode)
03014 {
03015 return pow(a,mpreal(b),rnd_mode);
03016 }
03017
03018 inline const mpreal pow(const unsigned long int a, const double b, mp_rnd_t rnd_mode)
03019 {
03020 return pow(a,mpreal(b),rnd_mode);
03021 }
03022
03023
03024 inline const mpreal pow(const unsigned int a, const unsigned long int b, mp_rnd_t rnd_mode)
03025 {
03026 return pow(static_cast<unsigned long int>(a),b,rnd_mode);
03027 }
03028
03029 inline const mpreal pow(const unsigned int a, const unsigned int b, mp_rnd_t rnd_mode)
03030 {
03031 return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);
03032 }
03033
03034 inline const mpreal pow(const unsigned int a, const long int b, mp_rnd_t rnd_mode)
03035 {
03036 if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);
03037 else return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03038 }
03039
03040 inline const mpreal pow(const unsigned int a, const int b, mp_rnd_t rnd_mode)
03041 {
03042 if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);
03043 else return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03044 }
03045
03046 inline const mpreal pow(const unsigned int a, const long double b, mp_rnd_t rnd_mode)
03047 {
03048 return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03049 }
03050
03051 inline const mpreal pow(const unsigned int a, const double b, mp_rnd_t rnd_mode)
03052 {
03053 return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03054 }
03055
03056
03057 inline const mpreal pow(const long int a, const unsigned long int b, mp_rnd_t rnd_mode)
03058 {
03059 if (a>0) return pow(static_cast<unsigned long int>(a),b,rnd_mode);
03060 else return pow(mpreal(a),b,rnd_mode);
03061 }
03062
03063 inline const mpreal pow(const long int a, const unsigned int b, mp_rnd_t rnd_mode)
03064 {
03065 if (a>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);
03066 else return pow(mpreal(a),static_cast<unsigned long int>(b),rnd_mode);
03067 }
03068
03069 inline const mpreal pow(const long int a, const long int b, mp_rnd_t rnd_mode)
03070 {
03071 if (a>0)
03072 {
03073 if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);
03074 else return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03075 }else{
03076 return pow(mpreal(a),b,rnd_mode);
03077 }
03078 }
03079
03080 inline const mpreal pow(const long int a, const int b, mp_rnd_t rnd_mode)
03081 {
03082 if (a>0)
03083 {
03084 if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);
03085 else return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03086 }else{
03087 return pow(mpreal(a),static_cast<long int>(b),rnd_mode);
03088 }
03089 }
03090
03091 inline const mpreal pow(const long int a, const long double b, mp_rnd_t rnd_mode)
03092 {
03093 if (a>=0) return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03094 else return pow(mpreal(a),mpreal(b),rnd_mode);
03095 }
03096
03097 inline const mpreal pow(const long int a, const double b, mp_rnd_t rnd_mode)
03098 {
03099 if (a>=0) return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03100 else return pow(mpreal(a),mpreal(b),rnd_mode);
03101 }
03102
03103
03104 inline const mpreal pow(const int a, const unsigned long int b, mp_rnd_t rnd_mode)
03105 {
03106 if (a>0) return pow(static_cast<unsigned long int>(a),b,rnd_mode);
03107 else return pow(mpreal(a),b,rnd_mode);
03108 }
03109
03110 inline const mpreal pow(const int a, const unsigned int b, mp_rnd_t rnd_mode)
03111 {
03112 if (a>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);
03113 else return pow(mpreal(a),static_cast<unsigned long int>(b),rnd_mode);
03114 }
03115
03116 inline const mpreal pow(const int a, const long int b, mp_rnd_t rnd_mode)
03117 {
03118 if (a>0)
03119 {
03120 if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);
03121 else return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03122 }else{
03123 return pow(mpreal(a),b,rnd_mode);
03124 }
03125 }
03126
03127 inline const mpreal pow(const int a, const int b, mp_rnd_t rnd_mode)
03128 {
03129 if (a>0)
03130 {
03131 if(b>0) return pow(static_cast<unsigned long int>(a),static_cast<unsigned long int>(b),rnd_mode);
03132 else return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03133 }else{
03134 return pow(mpreal(a),static_cast<long int>(b),rnd_mode);
03135 }
03136 }
03137
03138 inline const mpreal pow(const int a, const long double b, mp_rnd_t rnd_mode)
03139 {
03140 if (a>=0) return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03141 else return pow(mpreal(a),mpreal(b),rnd_mode);
03142 }
03143
03144 inline const mpreal pow(const int a, const double b, mp_rnd_t rnd_mode)
03145 {
03146 if (a>=0) return pow(static_cast<unsigned long int>(a),mpreal(b),rnd_mode);
03147 else return pow(mpreal(a),mpreal(b),rnd_mode);
03148 }
03149
03150
03151 inline const mpreal pow(const long double a, const long double b, mp_rnd_t rnd_mode)
03152 {
03153 return pow(mpreal(a),mpreal(b),rnd_mode);
03154 }
03155
03156 inline const mpreal pow(const long double a, const unsigned long int b, mp_rnd_t rnd_mode)
03157 {
03158 return pow(mpreal(a),b,rnd_mode);
03159 }
03160
03161 inline const mpreal pow(const long double a, const unsigned int b, mp_rnd_t rnd_mode)
03162 {
03163 return pow(mpreal(a),static_cast<unsigned long int>(b),rnd_mode);
03164 }
03165
03166 inline const mpreal pow(const long double a, const long int b, mp_rnd_t rnd_mode)
03167 {
03168 return pow(mpreal(a),b,rnd_mode);
03169 }
03170
03171 inline const mpreal pow(const long double a, const int b, mp_rnd_t rnd_mode)
03172 {
03173 return pow(mpreal(a),static_cast<long int>(b),rnd_mode);
03174 }
03175
03176 inline const mpreal pow(const double a, const double b, mp_rnd_t rnd_mode)
03177 {
03178 return pow(mpreal(a),mpreal(b),rnd_mode);
03179 }
03180
03181 inline const mpreal pow(const double a, const unsigned long int b, mp_rnd_t rnd_mode)
03182 {
03183 return pow(mpreal(a),b,rnd_mode);
03184 }
03185
03186 inline const mpreal pow(const double a, const unsigned int b, mp_rnd_t rnd_mode)
03187 {
03188 return pow(mpreal(a),static_cast<unsigned long int>(b),rnd_mode);
03189 }
03190
03191 inline const mpreal pow(const double a, const long int b, mp_rnd_t rnd_mode)
03192 {
03193 return pow(mpreal(a),b,rnd_mode);
03194 }
03195
03196 inline const mpreal pow(const double a, const int b, mp_rnd_t rnd_mode)
03197 {
03198 return pow(mpreal(a),static_cast<long int>(b),rnd_mode);
03199 }
03200
03201 }
03202
03203
03204
03205
03206 namespace std
03207 {
03208 template <>
03209 inline void swap(mpfr::mpreal& x, mpfr::mpreal& y)
03210 {
03211 return mpfr::swap(x, y);
03212 }
03213 }
03214
03215 #endif