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


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:00