CAPD::DynSys Library  6.0.0
capd::multiPrec::MpReal Class Reference

MpReal represents multiple precision real number with controlled rounding. More...

#include <capd/multiPrec/MpReal.h>

Public Types

typedef MpPrecision PrecisionType
 
typedef MpRoundingMode RoundingMode
 

Public Member Functions

 MpReal ()
 
 MpReal (double d, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (long double d, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (int i, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (unsigned int i, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (long int i, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (unsigned long int i, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (std::string s, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (const char *str, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (mpz_srcptr z, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (mpq_srcptr q, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (mpfr_t r, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 
 MpReal (const MpReal &r)
 
 ~MpReal ()
 
MpRealoperator= (const MpReal &r)
 Assignment operator. More...
 
void setPrecision (PrecisionType newprec)
 Sets precision for given MpReal object. More...
 
PrecisionType getPrecision () const
 returns precision of a given object More...
 
MpRealoperator+= (const MpReal &r)
 adds r using default rounding mode More...
 
MpRealoperator-= (const MpReal &r)
 substract r using default rounding mode More...
 
MpReal operator- () const
 
MpRealoperator*= (const MpReal &r)
 multiply r using default rounding mode More...
 
MpRealoperator/= (const MpReal &r)
 divides by r using default rounding mode More...
 
std::ostream & put (std::ostream &o, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision(), int base=10, int nb_digits=0) const
 writes to stream given number in the base with given number of digits and rounding mode More...
 
void get (const std::string &str, RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision(), int base=10)
 
MpReal pow (const unsigned long int e, RoundingMode rnd=MpReal::getDefaultRndMode()) const
 
MpReal pow (const long int e, RoundingMode rnd=MpReal::getDefaultRndMode()) const
 
MpReal pow (const MpReal &e, RoundingMode rnd=MpReal::getDefaultRndMode()) const
 
void random (PrecisionType prec=getDefaultPrecision())
 
MpReal leftBound ()
 
MpReal rightBound ()
 
bool contains (const MpReal &X)
 
bool containsInInterior (const MpReal &)
 

Static Public Member Functions

static void setDefaultPrecision (PrecisionType newprec)
 sets default precision for all operations More...
 
static PrecisionType getDefaultPrecision ()
 returns default precision of all operations More...
 
static void setDefaultRndMode (RoundingMode newrndmode)
 sets default rounding mode for all operations More...
 
static RoundingMode getDefaultRndMode ()
 return default rounding mode More...
 
static void roundUp ()
 sets rounding up mode More...
 
static void roundDown ()
 sets rounding down mode More...
 
static void roundNearest ()
 sets rounding to nearest mode More...
 
static void roundToZero ()
 sets rounding to zero mode More...
 
static void roundCut ()
 
static MpReal pi (RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 pi constant (3.1415...) with given precision and rounding direction More...
 
static MpReal log2 (RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 ln(2) - natural logarithm of 2 constant with given precision and rounding direction More...
 
static MpReal euler (RoundingMode rnd=getDefaultRndMode(), PrecisionType prec=getDefaultPrecision())
 euler constant (2.7...) with given precision and rounding direction More...
 
static MpReal positiveInfinity (PrecisionType prec=getDefaultPrecision())
 Positive infinity constant. More...
 
static MpReal negativeInfinity (PrecisionType prec=getDefaultPrecision())
 Negative infinity constant. More...
 
static void add (MpReal &res, const MpReal &r1, const MpReal &r2, RoundingMode rnd=getDefaultRndMode())
 adds r1 and r2 using precision of the res and given rounding mode More...
 
static void sub (MpReal &res, const MpReal &r1, const MpReal &r2, RoundingMode rnd=getDefaultRndMode())
 substract r1 and r2 using precision of the res and given rounding mode More...
 
static void neg (MpReal &res, const MpReal &r, RoundingMode rnd=getDefaultRndMode())
 
static void mul (MpReal &res, const MpReal &r1, const MpReal &r2, RoundingMode rnd=getDefaultRndMode())
 multiply r1 and r2 using precision of the res and given rounding mode More...
 
static void div (MpReal &res, const MpReal &r1, const MpReal &r2, RoundingMode rnd=getDefaultRndMode())
 divides r1 by r2 using precision of the res and given rounding mode More...
 
static void fma (MpReal &res, const MpReal &r1, const MpReal &r2, const MpReal &r3, RoundingMode rnd=getDefaultRndMode())
 fast multiplication and addition res = r1*r2 + r3 More...
 

Static Public Attributes

static const RoundingMode RoundUp =mp_rnd_t(GMP_RNDU)
 
static const RoundingMode RoundDown =mp_rnd_t(GMP_RNDD)
 
static const RoundingMode RoundNearest =mp_rnd_t(GMP_RNDN)
 
static const RoundingMode RoundToZero =mp_rnd_t(GMP_RNDZ)
 

Protected Attributes

mpfr_t mpfr_rep
 

Friends

bool isinf (const MpReal &r)
 
bool isnan (const MpReal &r)
 
MpReal copysign (const MpReal &x, const MpReal &y)
 Produce a value with the magnitude of x and sign bit of y: (-1)^signbit(y) * abs(x) More...
 
int signbit (const MpReal &x)
 
bool isZero (const MpReal &r)
 
bool isInf (const MpReal &r)
 
bool isNaN (const MpReal &r)
 
bool isNumber (const MpReal &r)
 
bool isSingular (const MpReal &r)
 
int sign (const MpReal &r)
 
int compare (const MpReal &r1, const MpReal &r2)
 compare two MpReals returns 0 if r1==r2, negative value if r1<r2 and positive value if r1>r2 More...
 
int compare (const MpReal &r1, const double r2)
 
int compare (const MpReal &r1, const int r2)
 
int compare (const MpReal &r1, const unsigned int r2)
 
int compare (const MpReal &r1, const long int r2)
 
int compare (const MpReal &r1, const unsigned long int r2)
 
MpReal operator+ (const MpReal &r1, const MpReal &r2)
 adds r1 and r2 using default precision and rounding mode More...
 
MpReal operator- (const MpReal &r1, const MpReal &r2)
 substract r1 and r2 using default precision and rounding mode More...
 
MpReal operator* (const MpReal &r1, const MpReal &r2)
 multiply r1 and r2 using default precision and rounding mode More...
 
MpReal operator/ (const MpReal &r1, const MpReal &r2)
 divides r1 by r2 using default precision and rounding mode More...
 
std::istream & operator>> (std::istream &i, MpReal &r)
 reads number from a stream More...
 
std::ostream & operator<< (std::ostream &o, const MpReal &r)
 writes number to a stream More...
 
MpReal round (const MpReal &r)
 
MpReal floor (const MpReal &r)
 
MpReal trunc (const MpReal &r)
 
MpReal ceil (const MpReal &r)
 
MpReal frac (const MpReal &r)
 

Detailed Description

MpReal represents multiple precision real number with controlled rounding.

It is a C++ wrapper for a C library mpfr

Member Typedef Documentation

◆ PrecisionType

◆ RoundingMode

Constructor & Destructor Documentation

◆ MpReal() [1/13]

capd::multiPrec::MpReal::MpReal ( )
inline

◆ MpReal() [2/13]

capd::multiPrec::MpReal::MpReal ( double  d,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inline

◆ MpReal() [3/13]

capd::multiPrec::MpReal::MpReal ( long double  d,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inline

◆ MpReal() [4/13]

capd::multiPrec::MpReal::MpReal ( int  i,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inline

◆ MpReal() [5/13]

capd::multiPrec::MpReal::MpReal ( unsigned int  i,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inline

◆ MpReal() [6/13]

capd::multiPrec::MpReal::MpReal ( long int  i,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inline

◆ MpReal() [7/13]

capd::multiPrec::MpReal::MpReal ( unsigned long int  i,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inline

◆ MpReal() [8/13]

capd::multiPrec::MpReal::MpReal ( std::string  s,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inline

◆ MpReal() [9/13]

capd::multiPrec::MpReal::MpReal ( const char *  str,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inline

◆ MpReal() [10/13]

capd::multiPrec::MpReal::MpReal ( mpz_srcptr  z,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)

◆ MpReal() [11/13]

capd::multiPrec::MpReal::MpReal ( mpq_srcptr  q,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)

◆ MpReal() [12/13]

capd::multiPrec::MpReal::MpReal ( mpfr_t  r,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)

◆ MpReal() [13/13]

capd::multiPrec::MpReal::MpReal ( const MpReal r)
inline

◆ ~MpReal()

capd::multiPrec::MpReal::~MpReal ( )
inline

Member Function Documentation

◆ add()

void capd::multiPrec::MpReal::add ( MpReal res,
const MpReal r1,
const MpReal r2,
RoundingMode  rnd = getDefaultRndMode() 
)
inlinestatic

adds r1 and r2 using precision of the res and given rounding mode

◆ contains()

bool capd::multiPrec::MpReal::contains ( const MpReal X)
inline

◆ containsInInterior()

bool capd::multiPrec::MpReal::containsInInterior ( const MpReal )
inline

◆ div()

void capd::multiPrec::MpReal::div ( MpReal res,
const MpReal r1,
const MpReal r2,
RoundingMode  rnd = getDefaultRndMode() 
)
inlinestatic

divides r1 by r2 using precision of the res and given rounding mode

◆ euler()

MpReal capd::multiPrec::MpReal::euler ( RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inlinestatic

euler constant (2.7...) with given precision and rounding direction

◆ fma()

void capd::multiPrec::MpReal::fma ( MpReal res,
const MpReal r1,
const MpReal r2,
const MpReal r3,
RoundingMode  rnd = getDefaultRndMode() 
)
inlinestatic

fast multiplication and addition res = r1*r2 + r3

res = r1*r2+r3

◆ get()

void capd::multiPrec::MpReal::get ( const std::string &  str,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision(),
int  base = 10 
)
inline

◆ getDefaultPrecision()

MpReal::PrecisionType capd::multiPrec::MpReal::getDefaultPrecision ( )
inlinestatic

returns default precision of all operations

◆ getDefaultRndMode()

MpReal::RoundingMode capd::multiPrec::MpReal::getDefaultRndMode ( )
inlinestatic

return default rounding mode

◆ getPrecision()

MpReal::PrecisionType capd::multiPrec::MpReal::getPrecision ( ) const
inline

returns precision of a given object

◆ leftBound()

MpReal capd::multiPrec::MpReal::leftBound ( )
inline

◆ log2()

MpReal capd::multiPrec::MpReal::log2 ( RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inlinestatic

ln(2) - natural logarithm of 2 constant with given precision and rounding direction

◆ mul()

void capd::multiPrec::MpReal::mul ( MpReal res,
const MpReal r1,
const MpReal r2,
RoundingMode  rnd = getDefaultRndMode() 
)
inlinestatic

multiply r1 and r2 using precision of the res and given rounding mode

◆ neg()

void capd::multiPrec::MpReal::neg ( MpReal res,
const MpReal r,
RoundingMode  rnd = getDefaultRndMode() 
)
inlinestatic

◆ negativeInfinity()

MpReal capd::multiPrec::MpReal::negativeInfinity ( PrecisionType  prec = getDefaultPrecision())
inlinestatic

Negative infinity constant.

◆ operator*=()

MpReal & capd::multiPrec::MpReal::operator*= ( const MpReal r)
inline

multiply r using default rounding mode

◆ operator+=()

MpReal & capd::multiPrec::MpReal::operator+= ( const MpReal r)
inline

adds r using default rounding mode

◆ operator-()

MpReal capd::multiPrec::MpReal::operator- ( ) const
inline

◆ operator-=()

MpReal & capd::multiPrec::MpReal::operator-= ( const MpReal r)
inline

substract r using default rounding mode

◆ operator/=()

MpReal & capd::multiPrec::MpReal::operator/= ( const MpReal r)
inline

divides by r using default rounding mode

◆ operator=()

MpReal & capd::multiPrec::MpReal::operator= ( const MpReal r)
inline

Assignment operator.

◆ pi()

MpReal capd::multiPrec::MpReal::pi ( RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision() 
)
inlinestatic

pi constant (3.1415...) with given precision and rounding direction

◆ positiveInfinity()

MpReal capd::multiPrec::MpReal::positiveInfinity ( PrecisionType  prec = getDefaultPrecision())
inlinestatic

Positive infinity constant.

◆ pow() [1/3]

MpReal capd::multiPrec::MpReal::pow ( const long int  e,
MpReal::RoundingMode  rnd = MpReal::getDefaultRndMode() 
) const
inline

◆ pow() [2/3]

MpReal capd::multiPrec::MpReal::pow ( const MpReal e,
MpReal::RoundingMode  rnd = MpReal::getDefaultRndMode() 
) const
inline

◆ pow() [3/3]

MpReal capd::multiPrec::MpReal::pow ( const unsigned long int  e,
MpReal::RoundingMode  rnd = MpReal::getDefaultRndMode() 
) const
inline

◆ put()

std::ostream & capd::multiPrec::MpReal::put ( std::ostream &  o,
RoundingMode  rnd = getDefaultRndMode(),
PrecisionType  prec = getDefaultPrecision(),
int  base = 10,
int  nb_digits = 0 
) const
inline

writes to stream given number in the base with given number of digits and rounding mode

◆ random()

void capd::multiPrec::MpReal::random ( PrecisionType  prec = getDefaultPrecision())

◆ rightBound()

MpReal capd::multiPrec::MpReal::rightBound ( )
inline

◆ roundCut()

void capd::multiPrec::MpReal::roundCut ( )
inlinestatic

◆ roundDown()

void capd::multiPrec::MpReal::roundDown ( )
inlinestatic

sets rounding down mode

◆ roundNearest()

void capd::multiPrec::MpReal::roundNearest ( )
inlinestatic

sets rounding to nearest mode

◆ roundToZero()

static void capd::multiPrec::MpReal::roundToZero ( )
static

sets rounding to zero mode

◆ roundUp()

void capd::multiPrec::MpReal::roundUp ( )
inlinestatic

sets rounding up mode

◆ setDefaultPrecision()

void capd::multiPrec::MpReal::setDefaultPrecision ( MpReal::PrecisionType  newprec)
inlinestatic

sets default precision for all operations

◆ setDefaultRndMode()

void capd::multiPrec::MpReal::setDefaultRndMode ( RoundingMode  newrndmode)
inlinestatic

sets default rounding mode for all operations

◆ setPrecision()

void capd::multiPrec::MpReal::setPrecision ( MpReal::PrecisionType  newprec)
inline

Sets precision for given MpReal object.

◆ sub()

void capd::multiPrec::MpReal::sub ( MpReal res,
const MpReal r1,
const MpReal r2,
RoundingMode  rnd = getDefaultRndMode() 
)
inlinestatic

substract r1 and r2 using precision of the res and given rounding mode

Friends And Related Function Documentation

◆ ceil

MpReal ceil ( const MpReal r)
friend

◆ compare [1/6]

int compare ( const MpReal r1,
const double  r2 
)
friend

◆ compare [2/6]

int compare ( const MpReal r1,
const int  r2 
)
friend

◆ compare [3/6]

int compare ( const MpReal r1,
const long int  r2 
)
friend

◆ compare [4/6]

int compare ( const MpReal r1,
const MpReal r2 
)
friend

compare two MpReals returns 0 if r1==r2, negative value if r1<r2 and positive value if r1>r2

Parameters
[in]r1,r2numbers to be compared
Returns
negative number if r1 < r2 0 if r1 == r2 positive number if r1 > r2

◆ compare [5/6]

int compare ( const MpReal r1,
const unsigned int  r2 
)
friend

◆ compare [6/6]

int compare ( const MpReal r1,
const unsigned long int  r2 
)
friend

◆ copysign

MpReal copysign ( const MpReal x,
const MpReal y 
)
friend

Produce a value with the magnitude of x and sign bit of y: (-1)^signbit(y) * abs(x)

◆ floor

MpReal floor ( const MpReal r)
friend

◆ frac

MpReal frac ( const MpReal r)
friend

◆ isinf

bool isinf ( const MpReal r)
friend

◆ isInf

bool isInf ( const MpReal r)
friend

◆ isnan

bool isnan ( const MpReal r)
friend

◆ isNaN

bool isNaN ( const MpReal r)
friend

◆ isNumber

bool isNumber ( const MpReal r)
friend

◆ isSingular

bool isSingular ( const MpReal r)
friend

◆ isZero

bool isZero ( const MpReal r)
friend

◆ operator*

MpReal operator* ( const MpReal r1,
const MpReal r2 
)
friend

multiply r1 and r2 using default precision and rounding mode

◆ operator+

MpReal operator+ ( const MpReal r1,
const MpReal r2 
)
friend

adds r1 and r2 using default precision and rounding mode

◆ operator-

MpReal operator- ( const MpReal r1,
const MpReal r2 
)
friend

substract r1 and r2 using default precision and rounding mode

◆ operator/

MpReal operator/ ( const MpReal r1,
const MpReal r2 
)
friend

divides r1 by r2 using default precision and rounding mode

◆ operator<<

std::ostream& operator<< ( std::ostream &  o,
const MpReal r 
)
friend

writes number to a stream

◆ operator>>

std::istream& operator>> ( std::istream &  i,
MpReal r 
)
friend

reads number from a stream

◆ round

MpReal round ( const MpReal r)
friend

◆ sign

int sign ( const MpReal r)
friend

◆ signbit

int signbit ( const MpReal x)
friend

◆ trunc

MpReal trunc ( const MpReal r)
friend

Member Data Documentation

◆ mpfr_rep

mpfr_t capd::multiPrec::MpReal::mpfr_rep
protected

◆ RoundDown

const RoundingMode capd::multiPrec::MpReal::RoundDown =mp_rnd_t(GMP_RNDD)
static

◆ RoundNearest

const RoundingMode capd::multiPrec::MpReal::RoundNearest =mp_rnd_t(GMP_RNDN)
static

◆ RoundToZero

const RoundingMode capd::multiPrec::MpReal::RoundToZero =mp_rnd_t(GMP_RNDZ)
static

◆ RoundUp

const RoundingMode capd::multiPrec::MpReal::RoundUp =mp_rnd_t(GMP_RNDU)
static

The documentation for this class was generated from the following files: