Multiprecision floats¶
Note
The functionality described in this section is available only if mp++ was configured
with the MPPP_WITH_MPFR
option enabled (see the installation instructions).
New in version 0.5.
#include <mp++/real.hpp>
The real
class¶

class
real
¶ Multiprecision floatingpoint class.
This class represents arbitraryprecision real values encoded in a binary floatingpoint format. It acts as a wrapper around the MPFR
mpfr_t
type, pairing a multiprecision significand (whose size can be set at runtime) to a fixedsize exponent. In other words,real
values can have an arbitrary number of binary digits of precision (limited only by the available memory), but the exponent range is limited.real
aims to behave like a C++ floatingpoint type whose precision is a runtime property of the class instances rather than a compiletime property of the type. Because of this, the way precision is handled inreal
differs from the way it is managed in MPFR. The most important difference is that in operations involvingreal
the precision of the result is usually determined by the precision of the operands, whereas in MPFR the precision of the operation is determined by the precision of the return value (which is always passed as the first function parameter in the MPFR API). For instance, in the following code,auto x = real{5,200} + real{6,150};
the first operand has a value of 5 and precision of 200 bits, while the second operand has a value of 6 and precision 150 bits. The precision of the result
x
(and the precision at which the addition is computed) will be the maximum precision among the two operands, that is, \(\mathrm{max}\left(200,150\right)=200\) bits.The precision of a
real
can be set at construction, or it can be changed later via functions and methods such asmppp::real::set_prec()
,mppp::real::prec_round()
, etc. By default, the precision of areal
is automatically deduced upon construction following a set of heuristics aimed at ensuring that the constructedreal
represents exactly the value used for initialisation. For instance, by default, the construction of areal
from a 32 bit integer will yield areal
with a precision of 32 bits. This behaviour can be altered either by specifying explicitly the desired precision value, or by setting a global default precision viareal_set_default_prec()
.This class has the look and feel of a C++ builtin type: it can interact with all of C++’s integral and floatingpoint primitive types,
integer
,rational
andreal128
(see theRealInteroperable
concept), and it provides overloaded operators. Differently from the builtin types, however, this class does not allow any implicit conversion to/from other types (apart frombool
): construction from and conversion to primitive types must always be requested explicitly. As a side effect, syntax such asreal r = 5; int m = r;
will not work, and direct initialization should be used instead:
real r{5}; int m{r};
Most of the functionality is exposed via plain functions, with the general convention that the functions are named after the corresponding MPFR functions minus the leading
mpfr_
prefix. For instance, the MPFR callmpfr_add(rop,a,b,MPFR_RNDN);
that writes the result of
a + b
, rounded to nearest, intorop
, becomes simplyadd(rop,a,b);
where the
add()
function is resolved via argumentdependent lookup. Function calls with overlapping arguments are allowed, unless noted otherwise. Unless otherwise specified, thereal
API always rounds to nearest (that is, theMPFR_RNDN
rounding mode is used).Multiple overloads of the same functionality are often available. Binary functions in MPFR are usually implemented via threeoperands functions, in which the first operand is a reference to the return value. The exponentiation function
mpfr_pow()
, for instance, takes three operands: the return value, the base and the exponent. There are two overloads of the corresponding exponentiation function forreal
:a ternary overload similar to
mpfr_pow()
,a binary overload taking as inputs the base and the exponent, and returning the result of the exponentiation.
This allows to avoid having to set up a return value for oneoff invocations of
pow()
(the binary overload will do it for you). For example:real r1, r2, r3{3}, r4{2}; pow(r1,r3,r4); // Ternary pow(): computes 3**2 and stores // the result in r1. r2 = pow(r3,r4); // Binary pow(): returns 3**2, which is then // assigned to r2.
In case of unary functions, there are often three overloads available:
a binary overload taking as first parameter a reference to the return value (MPFR style),
a unary overload returning the result of the operation,
a nullary member function that modifies the calling object inplace.
For instance, here are three possible ways of computing the absolute value:
real r1, r2, r3{5}; abs(r1,r3); // Binary abs(): computes and stores the absolute value // of r3 into r1. r2 = abs(r3); // Unary abs(): returns the absolute value of r3, which is // then assigned to r2. r3.abs(); // Member function abs(): replaces the value of r3 with its // absolute value.
Note that at this time a subset of the MPFR API has been wrapped by
real
.Various overloaded operators are provided. The arithmetic operators always return a
real
result. The relational operators,==
,!=
,<
,>
,<=
and>=
will promote nonreal
arguments toreal
before performing the comparison. Alternative comparison functions treating NaNs specially are provided for use in the C++ standard library (and wherever strict weak ordering relations are needed).Member functions are provided to access directly the internal
mpfr_t
instance (seemppp::real::get_mpfr_t()
andmppp::real::_get_mpfr_t()
), so that it is possible to use transparently the MPFR API withreal
objects.Public Functions

real
()¶ Default constructor.
The value will be initialised to positive zero. The precision of
this
will be either the default precision, if set, or the value returned byreal_prec_min()
otherwise.

real
(const real &other)¶ Copy constructor.
The copy constructor performs an exact deep copy of the input object.
 Parameters
other
: the real that will be copied.

real
(const real &other, mpfr_prec_t p)¶ Copy constructor with custom precision.
This constructor will set
this
to a copy ofother
with precisionp
. Ifp
is smaller than the precision ofother
, a rounding operation will be performed, otherwise the value will be copied exactly. Parameters
other
: the real that will be copied.p
: the desired precision.
 Exceptions
std::invalid_argument
: ifp
is outside the range established by real_prec_min() and real_prec_max().

real
(real &&other)¶ Move constructor.
Warning
Unless otherwise noted, the only valid operations on the movedfrom
other
object are destruction and copy/move assignment. After reassignment,other
can be used normally again. Parameters
other
: the real that will be moved.

real
(real_kind k, int sign, mpfr_prec_t p)¶ Constructor from a special value, sign and precision.
This constructor will initialise
this
with one of the special values specified by thereal_kind
enum. The precision ofthis
will bep
. Ifp
is zero, the precision will be set to the default precision (as indicated byreal_get_default_prec()
).If
k
is not NaN, the sign bit will be set to positive ifsign
is nonnegative, negative otherwise. Parameters
k
: the desired special value.sign
: the desired sign forthis
.p
: the desired precision forthis
.
 Exceptions
std::invalid_argument
: ifp
is not within the bounds established by real_prec_min() and real_prec_max(), or ifp
is zero but no default precision has been set.

real
(real_kind k, mpfr_prec_t p)¶ Constructor from a special value and precision.
This constructor is equivalent to the constructor from a special value, sign and precision with a hardcoded sign of 0.
 Parameters
k
: the desired special value.p
: the desired precision forthis
.
 Exceptions
unspecified
: any exception thrown by the constructor from a special value, sign and precision.

real
(real_kind k)¶ Constructor from a special value.
This constructor is equivalent to the constructor from a special value, sign and precision with a hardcoded sign of 0 and hardcoded precision of 0.
 Parameters
k
: the desired special value.
 Exceptions
unspecified
: any exception thrown by the constructor from a special value, sign and precision.

template<RealInteroperable
T
>real
(const T &x, mpfr_prec_t p = 0)¶ Generic constructor.
The generic constructor will set
this
to the value ofx
with a precision ofp
.If
p
is nonzero, thenthis
will be initialised exactly to a precision ofp
, and a rounding operation might occurr.If
p
is zero, the constructor will first fetch the default precisiondp
viareal_get_default_prec()
. Ifdp
is nonzero, thendp
will be used as precision forthis
and a rounding operation might occurr.Otherwise, if
dp
is zero, the precision ofthis
will be set according to the following heuristics:if
x
is a C++ integral typeI
, then the precision is set to the bit width ofI
;if
x
is a C++ floatingpoint typeF
, then the precision is set to the number of binary digits in the significand ofF
;if
x
isinteger
, then the precision is set to the number of bits in use byx
(rounded up to the next multiple of the limb type’s bit width);if
x
isrational
, then the precision is set to the sum of the number of bits used by numerator and denominator (as established by the previous heuristic forinteger
);if
x
isreal128
, then the precision is set to 113.
These heuristics aim at ensuring that, whatever the type of
x
, its value is preserved exactly in the constructedreal
.Construction from
bool
will initialisethis
to 1 fortrue
, and 0 forfalse
. Parameters
x
: the construction argument.p
: the desired precision.
 Exceptions
std::overflow_error
: if an overflow occurs in the computation of the automaticallydeduced precision.std::invalid_argument
: ifp
is nonzero and outside the range established by real_prec_min() and real_prec_max().

template<StringType
T
>real
(const T &s, int base, mpfr_prec_t p)¶ Constructor from string, base and precision.
This constructor will set
this
to the value represented by theStringType
s
, which is interpreted as a floatingpoint number in basebase
.base
must be either zero (in which case the base will be automatically deduced) or a number in the [2,62] range. The valid string formats are detailed in the documentation of the MPFR functionmpfr_set_str()
. Note that leading whitespaces are ignored, but trailing whitespaces will raise an error.The precision of
this
will bep
ifp
is nonzero, the default precision otherwise. Ifp
is zero and no default precision has been set, an error will be raised. Parameters
s
: the input string.base
: the base used in the string representation.p
: the desired precision.
 Exceptions
std::invalid_argument
: in the following cases:base
is not zero and not in the [2,62] range,p
is either outside the valid bounds for a precision value, or it is zero and no default precision value has been set,s
cannot be interpreted as a floatingpoint number.
unspecified
: any exception thrown by memory errors in standard containers.

template<StringType
T
>real
(const T &s, mpfr_prec_t p)¶ Constructor from string and precision.
This constructor is equivalent to the constructor from string with a
base
value hardcoded to 10. Parameters
s
: the input string.p
: the desired precision.
 Exceptions
unspecified
: any exception thrown by the constructor from string, base and precision.

template<StringType
T
>real
(const T &s)¶ Constructor from string.
This constructor is equivalent to the constructor from string with a
base
value hardcoded to 10 and a precision value hardcoded to zero (that is, the precision will be the default precision, if set). Parameters
s
: the input string.
 Exceptions
unspecified
: any exception thrown by the constructor from string, base and precision.

real
(const char *begin, const char *end, int base, mpfr_prec_t p)¶ Constructor from range of characters, base and precision.
This constructor will initialise
this
from the content of the input halfopen range, which is interpreted as the string representation of a floatingpoint value in basebase
.Internally, the constructor will copy the content of the range to a local buffer, add a string terminator, and invoke the constructor from string, base and precision.
 Parameters
begin
: the start of the input range.end
: the end of the input range.base
: the base used in the string representation.p
: the desired precision.
 Exceptions
unspecified
: any exception thrown by the constructor from string, or by memory allocation errors in standard containers.

real
(const char *begin, const char *end, mpfr_prec_t p)¶ Constructor from range of characters and precision.
This constructor is equivalent to the constructor from range of characters with a
base
value hardcoded to 10. Parameters
begin
: the start of the input range.end
: the end of the input range.p
: the desired precision.
 Exceptions
unspecified
: any exception thrown by the constructor from range of characters, base and precision.

real
(const char *begin, const char *end)¶ Constructor from range of characters.
This constructor is equivalent to the constructor from range of characters with a
base
value hardcoded to 10 and a precision value hardcoded to zero (that is, the precision will be the default precision, if set). Parameters
begin
: the start of the input range.end
: the end of the input range.
 Exceptions
unspecified
: any exception thrown by the constructor from range of characters, base and precision.

real
(const mpfr_t x)¶ Copy constructor from
mpfr_t
.This constructor will initialise
this
with an exact deep copy ofx
.Warning
It is the user’s responsibility to ensure that
x
has been correctly initialised with a precision within the bounds established byreal_prec_min()
andreal_prec_max()
. Parameters
x
: thempfr_t
that will be deepcopied.

real
(mpfr_t &&x)¶ Move constructor from
mpfr_t
.This constructor will initialise
this
with a shallow copy ofx
.Warning
It is the user’s responsibility to ensure that
x
has been correctly initialised with a precision within the bounds established byreal_prec_min()
andreal_prec_max()
.Additionally, the user must ensure that, after construction,
mpfr_clear()
is never called onx
: the resources previously owned byx
are now owned bythis
, which will take care of releasing them when the destructor is called. Parameters
x
: thempfr_t
that will be moved.

~real
()¶ Destructor.
The destructor will free any resource held by the internal
mpfr_t
instance.

real &
operator=
(const real &other)¶ Copy assignment operator.
The operator will deepcopy
other
intothis
. Return
a reference to
this
. Parameters
other
: the real that will be copied intothis
.

real &
operator=
(real &&other)¶ Move assignment operator.
 Return
a reference to
this
. Parameters
other
: the real that will be moved intothis
.

template<RealInteroperable
T
>
real &operator=
(const T &x)¶ Generic assignment operator.
The generic assignment operator will set
this
to the value ofx
.The operator will first fetch the default precision
dp
viareal_get_default_prec()
. Ifdp
is nonzero, thendp
will be used as a new precision forthis
and a rounding operation might occurr during the assignment.Otherwise, if
dp
is zero, the precision ofthis
will be set according to the same heuristics described in the generic constructor. Return
a reference to
this
. Parameters
x
: the assignment argument.
 Exceptions
std::overflow_error
: if an overflow occurs in the computation of the automaticallydeduced precision.

template<StringType
T
>
real &operator=
(const T &s)¶ Assignment from string.
This operator will set
this
to the value represented by theStringType
s
, which is interpreted as a floatingpoint number in base 10. The precision ofthis
will be set to the value returned byreal_get_default_prec()
. If no default precision has been set, an error will be raised. Ifs
is not a valid representation of a floatingpoint number in base 10,this
will be set to NaN and an error will be raised. Return
a reference to
this
. Parameters
s
: the string that will be assigned tothis
.
 Exceptions
std::invalid_argument
: if a default precision has not been set, or ifs
cannot be parsed as a floatingpoint value in base 10.unspecified
: any exception thrown by memory allocation errors in standard containers.

real &
operator=
(const mpfr_t x)¶ Copy assignment from
mpfr_t
.This operator will set
this
to a deep copy ofx
.Warning
It is the user’s responsibility to ensure that
x
has been correctly initialised with a precision within the bounds established byreal_prec_min()
andreal_prec_max()
. Return
a reference to
this
. Parameters
x
: thempfr_t
that will be copied.

real &
operator=
(mpfr_t &&x)¶ Move assignment from
mpfr_t
.This operator will set
this
to a shallow copy ofx
.Warning
It is the user’s responsibility to ensure that
x
has been correctly initialised with a precision within the bounds established byreal_prec_min()
andreal_prec_max()
.Additionally, the user must ensure that, after the assignment,
mpfr_clear()
is never called onx
: the resources previously owned byx
are now owned bythis
, which will take care of releasing them when the destructor is called. Return
a reference to
this
. Parameters
x
: thempfr_t
that will be moved.

real &
set
(const real &other)¶ Set to another real value.
This method will set
this
to the value ofother
. Contrary to the copy assignment operator, the precision of the assignment is dictated by the precision ofthis
, rather than the precision ofother
. Consequently, the precision ofthis
will not be altered by the assignment, and a rounding might occur, depending on the values and the precisions of the operands.This method is a thin wrapper around the
mpfr_set()
assignment function from the MPFR API. Return
a reference to
this
. Parameters
other
: the value to whichthis
will be set.

template<RealInteroperable
T
>
real &set
(const T &x)¶ Generic setter.
This method will set
this
to the value ofx
. Contrary to the generic assignment operator, the precision of the assignment is dictated by the precision ofthis
, rather than being deduced from the type and value ofx
. Consequently, the precision ofthis
will not be altered by the assignment, and a rounding might occur, depending on the operands.This method is a thin wrapper around various
mpfr_set_*()
assignment functions from the MPFR API. Return
a reference to
this
. Parameters
x
: the value to whichthis
will be set.

template<StringType
T
>
real &set
(const T &s, int base = 10)¶ Setter to string.
This method will set
this
to the value represented by theStringType
s
, which will be interpreted as a floatingpoint number in basebase
.base
must be either 0 (in which case the base is automatically deduced), or a value in the [2,62] range. Contrary to the assignment operator from string, the global default precision is ignored and the precision of the assignment is dictated by the precision ofthis
. Consequently, the precision ofthis
will not be altered by the assignment, and a rounding might occur, depending on the operands.If
s
is not a valid representation of a floatingpoint number in basebase
,this
will be set to NaN and an error will be raised.This method is a thin wrapper around the
mpfr_set_str()
assignment function from the MPFR API. Return
a reference to
this
. Parameters
s
: the string to whichthis
will be set.base
: the base used in the string representation.
 Exceptions
std::invalid_argument
: ifs
cannot be parsed as a floatingpoint value in base 10, or if the value ofbase
is invalid.unspecified
: any exception thrown by memory allocation errors in standard containers.

real &
set
(const char *begin, const char *end, int base = 10)¶ Set to character range.
This setter will set
this
to the content of the input halfopen range, which is interpreted as the string representation of a floatingpoint value in basebase
.Internally, the setter will copy the content of the range to a local buffer, add a string terminator, and invoke the setter to string.
 Return
a reference to
this
. Parameters
begin
: the start of the input range.end
: the end of the input range.base
: the base used in the string representation.
 Exceptions
unspecified
: any exception thrown by the setter to string, or by memory allocation errors in standard containers.

real &
set
(const mpfr_t x)¶ Set to an
mpfr_t
.This method will set
this
to the value ofx
. Contrary to the corresponding assignment operator, the precision of the assignment is dictated by the precision ofthis
, rather than the precision ofx
. Consequently, the precision ofthis
will not be altered by the assignment, and a rounding might occur, depending on the values and the precisions of the operands.This method is a thin wrapper around the
mpfr_set()
assignment function from the MPFR API.Warning
It is the user’s responsibility to ensure that
x
has been correctly initialised. Return
a reference to
this
. Parameters
x
: thempfr_t
to whichthis
will be set.

real &
set_nan
()¶ Set to NaN.
This setter will set
this
to NaN with an unspecified sign bit. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
set_inf
(int sign = 0)¶ Set to infinity.
This setter will set
this
to infinity. The sign bit will be positive ifsign
is nonnegative, negative otherwise. The precision ofthis
will not be altered. Return
a reference to
this
. Parameters
sign
: the sign of the infinity to whichthis
will be set.

real &
set_zero
(int sign = 0)¶ Set to zero.
This setter will set
this
to zero. The sign bit will be positive ifsign
is nonnegative, negative otherwise. The precision ofthis
will not be altered. Return
a reference to
this
. Parameters
sign
: the sign of the zero to whichthis
will be set.

const mpfr_struct_t *
get_mpfr_t
() const¶ Const reference to the internal
mpfr_t
.This method will return a const pointer to the internal MPFR structure used to represent the value of
this
. The returned object can be used as aconst mpfr_t
function parameter in the MPFR API. Return
a const reference to the internal MPFR structure.

mpfr_struct_t *
_get_mpfr_t
()¶ Mutable reference to the internal
mpfr_t
.This method will return a mutable pointer to the internal MPFR structure used to represent the value of
this
. The returned object can be used as anmpfr_t
function parameter in the MPFR API.Warning
When using this mutable getter, it is the user’s responsibility to ensure that the internal MPFR structure is kept in a state which respects the invariants of the
real
class. Specifically, the precision value must be in the bounds established byreal_prec_min()
andreal_prec_max()
, and upon destruction areal
object must contain a validmpfr_t
object. Return
a mutable reference to the internal MPFR structure.

bool
nan_p
() const¶ Detect NaN.
 Return
true
ifthis
is NaN,false
otherwise.

bool
inf_p
() const¶ Detect infinity.
 Return
true
ifthis
is an infinity,false
otherwise.

bool
number_p
() const¶ Detect finite number.
 Return
true
ifthis
is a finite number (i.e., not NaN or infinity),false
otherwise.

bool
zero_p
() const¶ Detect zero.
 Return
true
ifthis
is zero,false
otherwise.

bool
regular_p
() const¶ Detect regular number.
 Return
true
ifthis
is a regular number (i.e., not NaN, infinity or zero),false
otherwise.

bool
is_one
() const¶ Detect one.
 Return
true
ifthis
is exactly equal to 1,false
otherwise.

int
sgn
() const¶ Detect sign.
 Return
a positive value if
this
is positive, zero ifthis
is zero, a negative value ifthis
is negative. Exceptions
std::domain_error
: ifthis
is NaN.

bool
signbit
() const¶ Get the sign bit.
The sign bit is set if
this
is negative, 0, or a NaN whose representation has its sign bit set. Return
the sign bit of
this
.

mpfr_prec_t
get_prec
() const¶ Get the precision of
this
. Return
the current precision (i.e., the number of binary digits in the significand) of
this
.

real &
abs
()¶ Inplace absolute value.
This method will set
this
to its absolute value. Return
a reference to
this
.

real &
set_prec
(mpfr_prec_t p)¶ Destructively set the precision.
This method will set the precision of
this
to exactlyp
bits. The value ofthis
will be set to NaN. Return
a reference to
this
. Parameters
p
: the desired precision.
 Exceptions
std::invalid_argument
: if the value ofp
is not in the range established by real_prec_min() and real_prec_max().

real &
prec_round
(mpfr_prec_t p)¶ Set the precision maintaining the current value.
This method will set the precision of
this
to exactlyp
bits. Ifp
is smaller than the current precision ofthis
, a rounding operation will be performed, otherwise the value will be preserved exactly. Return
a reference to
this
. Parameters
p
: the desired precision.
 Exceptions
std::invalid_argument
: if the value ofp
is not in the range established by real_prec_min() and real_prec_max().

template<RealInteroperable
T
>operator T
() const¶ Generic conversion operator.
This operator will convert
this
to aRealInteroperable
type. The conversion proceeds as follows:if
T
isbool
, then the conversion returnsfalse
ifthis
is zero,true
otherwise (including ifthis
is NaN);if
T
is a C++ integral type other thanbool
, the conversion will yield the truncated counterpart ofthis
(i.e., the conversion rounds to zero). The conversion may fail due to overflow or domain errors (i.e., when trying to convert nonfinite values);if
T
if a C++ floatingpoint type, the conversion calls directly the lowlevel MPFR functions (e.g.,mpfr_get_d()
), and might yield infinities for finite input values;if
T
isinteger
, the conversion rounds to zero and might fail due to domain errors, but it will never overflow;if
T
isrational
, the conversion may fail ifthis
is not finite or if the conversion produces an overflow in the manipulation of the exponent ofthis
(that is, if the absolute value ofthis
is very large or very small). If the conversion succeeds, it will be exact;if
T
isreal128
, the conversion might yield infinities for finite input values.
 Return
this
converted toT
. Exceptions
std::domain_error
: ifthis
is not finite and the target type cannot represent nonfinite numbers.std::overflow_error
: if the conversion results in overflow.

template<RealInteroperable
T
>
boolget
(T &rop) const¶ Generic conversion method.
This method, similarly to the conversion operator, will convert
this
to aRealInteroperable
type, storing the result of the conversion intorop
. Differently from the conversion operator, this method does not raise any exception: if the conversion is successful, the method will returntrue
, otherwise the method will returnfalse
. If the conversion fails,rop
will not be altered. Return
true
if the conversion succeeded,false
otherwise. The conversion can fail in the ways specified in the documentation of the conversion operator. Parameters
rop
: the variable which will store the result of the conversion.

std::string
to_string
(int base = 10) const¶ Convert to string.
This method will convert
this
to a string representation in basebase
. The returned string is guaranteed to produce exactly the original value when used in one of the constructors from string ofreal
(provided that the original precision and base are used in the construction). Return
this
converted to a string. Parameters
base
: the base to be used for the string representation.
 Exceptions
std::invalid_argument
: ifbase
is not in the [2,62] range.std::runtime_error
: if the call to thempfr_get_str()
function of the MPFR API fails.

real &
sqrt
()¶ Inplace square root.
This method will set
this
to its square root. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
rec_sqrt
()¶ Inplace reciprocal square root.
This method will set
this
to its reciprocal square root. The precision ofthis
will not be altered.If
this
is zero, the result will be a positive infinity (regardless of the sign ofthis
). Ifthis
is a positive infinity, the result will be +0. Ifthis
is negative, the result will be NaN. Return
a reference to
this
.

real &
cbrt
()¶ Inplace cubic root.
This method will set
this
to its cubic root. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
sin
()¶ Inplace sine.
This method will set
this
to its sine. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
cos
()¶ Inplace cosine.
This method will set
this
to its cosine. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
tan
()¶ Inplace tangent.
This method will set
this
to its tangent. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
sec
()¶ Inplace secant.
This method will set
this
to its secant. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
csc
()¶ Inplace cosecant.
This method will set
this
to its cosecant. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
cot
()¶ Inplace cotangent.
This method will set
this
to its cotangent. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
acos
()¶ Inplace arccosine.
This method will set
this
to its arccosine. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
asin
()¶ Inplace arcsine.
This method will set
this
to its arcsine. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
atan
()¶ Inplace arctangent.
This method will set
this
to its arctangent. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
cosh
()¶ Inplace hyperbolic cosine.
This method will set
this
to its hyperbolic cosine. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
sinh
()¶ Inplace hyperbolic sine.
This method will set
this
to its hyperbolic sine. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
tanh
()¶ Inplace hyperbolic tangent.
This method will set
this
to its hyperbolic tangent. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
sech
()¶ Inplace hyperbolic secant.
This method will set
this
to its hyperbolic secant. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
csch
()¶ Inplace hyperbolic cosecant.
This method will set
this
to its hyperbolic cosecant. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
coth
()¶ Inplace hyperbolic cotangent.
This method will set
this
to its hyperbolic cotangent. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
acosh
()¶ Inplace inverse hyperbolic cosine.
This method will set
this
to its inverse hyperbolic cosine. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
asinh
()¶ Inplace inverse hyperbolic sine.
This method will set
this
to its inverse hyperbolic sine. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
atanh
()¶ Inplace inverse hyperbolic tangent.
This method will set
this
to its inverse hyperbolic tangent. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
exp
()¶ Inplace exponential.
This method will set
this
to its exponential. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
exp2
()¶ Inplace base2 exponential.
This method will set
this
to2**this
. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
exp10
()¶ Inplace base10 exponential.
This method will set
this
to10**this
. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
expm1
()¶ Inplace exponential minus 1.
This method will set
this
to its exponential minus one. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
log
()¶ Inplace logarithm.
This method will set
this
to its logarithm. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
log2
()¶ Inplace base2 logarithm.
This method will set
this
to its base2 logarithm. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
log10
()¶ Inplace base10 logarithm.
This method will set
this
to its base10 logarithm. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
log1p
()¶ Inplace augmented logarithm.
This method will set
this
the logarithm ofthis + 1
. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
gamma
()¶ Inplace Gamma function.
This method will set
this
to its Gamma function. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
lngamma
()¶ Inplace logarithm of the Gamma function.
This method will set
this
to the logarithm of its Gamma function. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
lgamma
()¶ Inplace logarithm of the absolute value of the Gamma function.
This method will set
this
to the logarithm of the absolute value of its Gamma function. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
digamma
()¶ Inplace Digamma function.
This method will set
this
to its Digamma function. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
j0
()¶ Inplace Bessel function of the first kind of order 0.
This method will set
this
to its Bessel function of the first kind of order 0. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
j1
()¶ Inplace Bessel function of the first kind of order 1.
This method will set
this
to its Bessel function of the first kind of order 1. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
y0
()¶ Inplace Bessel function of the second kind of order 0.
This method will set
this
to its Bessel function of the second kind of order 0. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
y1
()¶ Inplace Bessel function of the second kind of order 1.
This method will set
this
to its Bessel function of the second kind of order 1. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
eint
()¶ Inplace exponential integral.
This method will set
this
to its exponential integral. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
li2
()¶ Inplace dilogarithm.
This method will set
this
to its dilogarithm. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
zeta
()¶ Inplace Riemann Zeta function.
This method will set
this
to its Riemann Zeta function. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
erf
()¶ Inplace error function.
This method will set
this
to its error function. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
erfc
()¶ Inplace complementary error function.
This method will set
this
to its complementary error function. The precision ofthis
will not be altered. Return
a reference to
this
.

real &
ai
()¶ Inplace Airy function.
This method will set
this
to its Airy function. The precision ofthis
will not be altered. Return
a reference to
this
.

bool
integer_p
() const¶ Check if the value is an integer.
 Return
true
ifthis
represents an integer value,false
otherwise.
Types¶

using
mppp
::
mpfr_struct_t
= std::remove_extent<mpfr_t>::type¶ The C structure used by MPFR to represent arbitraryprecision floats. The MPFR type
mpfr_t
is defined as an array of size 1 of this structure.

type
mpfr_prec_t
¶ An integral type defined by the MPFR library, used to represent the precision of
mpfr_t
and (by extension)real
objects.
Concepts¶

template<typename
T
>
conceptmppp
::
RealInteroperable
¶ This concept is satisfied if the type
T
can interoperate withreal
. Specifically, this concept will betrue
ifT
is either:a
CppInteroperable
type, oran
integer
, ora
rational
, or

template<typename
T
>
conceptmppp
::
CvrReal
¶ This concept is satisfied if the type
T
, after the removal of reference and cv qualifiers, is the same asmppp::real
.

template<typename ...
Args
>
conceptmppp
::
RealSetArgs
¶ This concept is satisfied if the types in the parameter pack
Args
can be used as argument types in one of themppp::real::set()
method overloads. In other words, this concept is satisfied if the expressionr.set(x, y, z, ...);
is valid (where
r
is a nonconstreal
andx
,y
,z
, etc. are const references to the types inArgs
).

template<typename
T
, typenameU
>
conceptmppp
::
RealOpTypes
¶ This concept is satisfied if the types
T
andU
are suitable for use in the generic binary operators and functions involvingreal
. Specifically, the concept will betrue
if either:T
andU
both satisfyCvrReal
,one type satisfies
CvrReal
and the other type, after the removal of reference and cv qualifiers, satisfiesRealInteroperable
.
A corresponding boolean type trait called
are_real_op_types
is also available (even if the compiler does not support concepts).

template<typename
T
, typenameU
>
conceptmppp
::
RealCompoundOpTypes
¶ This concept is satisfied if the types
T
andU
are suitable for use in the generic inplace operators involvingreal
. Specifically, the concept will betrue
ifT
andU
satisfyRealOpTypes
andT
, after the removal of reference, is not const.
Functions¶
Precision handling¶

constexpr mpfr_prec_t
mppp
::
real_prec_min
()¶ Minimum precision for a real.
This compiletime constant represents the minimum valid precision for a
real
. The returned value is guaranteed to be not less than theMPFR_PREC_MIN
MPFR constant. Return
the minimum valid precision for a real.

constexpr mpfr_prec_t
mppp
::
real_prec_max
()¶ Maximum precision for a real.
This compiletime constant represents the maximum valid precision for a
real
. The returned value is guaranteed to be not greater than theMPFR_PREC_MAX
MPFR constant. Return
the maximum valid precision for a real.

mpfr_prec_t
mppp
::
real_get_default_prec
()¶ Get the default precision for real objects.
This function returns the value of the precision used during the construction of
real
objects when an explicit precision value is not specified . On program startup, the value returned by this function is zero, meaning that the precision of areal
object will be chosen automatically according to heuristics depending on the specific situation, if possible.The default precision is stored in a global variable, and its value can be changed via
real_set_default_prec()
. It is safe to read and modify concurrently from multiple threads the default precision. Return
the value of the default precision for real objects.

void
mppp
::
real_set_default_prec
(mpfr_prec_t p)¶ Set the default precision for real objects.
See
real_get_default_prec()
for an explanation of how the default precision value is used. Parameters
p
: the desired value for the default precision for real objects.
 Exceptions
std::invalid_argument
: ifp
is nonzero and not in the range established by real_prec_min() and real_prec_max().

void
mppp
::
real_reset_default_prec
()¶ Reset the default precision for real objects.
This function will reset the default precision value to zero (i.e., the same value assigned on program startup). See
real_get_default_prec()
for an explanation of how the default precision value is used.

void
mppp
::
set_prec
(real &r, mpfr_prec_t p)¶ Destructively set the precision of a real.
This function will set the precision of
r
to exactlyp
bits. The value ofr
will be set to NaN. Parameters
r
: the real whose precision will be set.p
: the desired precision.
 Exceptions
unspecified
: any exception thrown by mppp::real::set_prec().

void
mppp
::
prec_round
(real &r, mpfr_prec_t p)¶ Set the precision of a real maintaining the current value.
This function will set the precision of
r
to exactlyp
bits. Ifp
is smaller than the current precision ofr
, a rounding operation will be performed, otherwise the value will be preserved exactly. Parameters
r
: the real whose precision will be set.p
: the desired precision.
 Exceptions
unspecified
: any exception thrown by mppp::real::prec_round().

mpfr_prec_t
mppp
::
get_prec
(const real &r)¶ Get the precision of a real.
 Return
the precision of
r
. Parameters
r
: the real whose precision will be returned.
Assignment¶

template<RealSetArgs...
Args
>
real &mppp
::
set
(real &r, const Args&... args)¶ Generic setter for real.
This function will use the arguments
args
to set the value of thereal
r
, using one of the availablemppp::real::set()
overloads. That is, the body of this function is equivalent toreturn r.set(args...);
The input arguments must satisfy the
RealSetArgs
concept. Return
a reference to
r
. Parameters
r
: the real that will be set.args
: the arguments that will be passed to mppp::real::set().
 Exceptions
unspecified
: any exception thrown by the invoked mppp::real::set() overload.

template<std::size_t
SSize
>
real &mppp
::
set_z_2exp
(real &r, const integer<SSize> &n, mpfr_exp_t e)¶ Set real to \(n\times 2^e\).
This function will set
r
to \(n\times 2^e\). The precision ofr
will not be altered. Ifn
is zero, the result will be positive zero.

real &
mppp
::
set_nan
(real &r)¶ Set real to NaN.
This function will set
r
to NaN with an unspecified sign bit. The precision ofr
will not be altered. Return
a reference to
r
. Parameters
r
: the real argument.

real &
mppp
::
set_inf
(real &r, int sign = 0)¶ Set real to infinity.
This function will set
r
to infinity. The sign bit will be positive ifsign
is nonnegative, negative otherwise. The precision ofr
will not be altered. Return
a reference to
r
. Parameters
r
: the real argument.sign
: the sign of the infinity to whichr
will be set.

real &
mppp
::
set_zero
(real &r, int sign = 0)¶ Set real to zero.
This function will set
r
to zero. The sign bit will be positive ifsign
is nonnegative, negative otherwise. The precision ofr
will not be altered. Return
a reference to
r
. Parameters
r
: the real argument.sign
: the sign of the zero to whichr
will be set.
Conversion¶

template<RealInteroperable
T
>
boolmppp
::
get
(T &rop, const real &x)¶ Generic conversion function for real.
This function will convert the input
real
x
to aRealInteroperable
type, storing the result of the conversion intorop
. If the conversion is successful, the function will returntrue
, otherwise the function will returnfalse
. If the conversion fails,rop
will not be altered.

template<std::size_t
SSize
>
mpfr_exp_tmppp
::
get_z_2exp
(integer<SSize> &n, const real &r)¶ Extract the significand and the exponent of a real.
This function will extract the scaled significand of
r
inton
, and return the exponente
such thatr
equals \(n\times 2^e\).If
r
is not finite, an error will be raised.
Arithmetic¶

template<CvrReal
T
, CvrRealU
>
real &mppp
::
add
(real &rop, T &&a, U &&b)¶ Ternary real addition.
This function will compute \(a+b\), storing the result in
rop
. The precision of the result will be set to the largest precision among the operands. Return
a reference to
rop
. Parameters
rop
: the return value.a
: the first operand.b
: the second operand.

template<CvrReal
T
, CvrRealU
>
real &mppp
::
sub
(real &rop, T &&a, U &&b)¶ Ternary real subtraction.
This function will compute \(ab\), storing the result in
rop
. The precision of the result will be set to the largest precision among the operands. Return
a reference to
rop
. Parameters
rop
: the return value.a
: the first operand.b
: the second operand.

template<CvrReal
T
, CvrRealU
>
real &mppp
::
mul
(real &rop, T &&a, U &&b)¶ Ternary real multiplication.
This function will compute \(a \times b\), storing the result in
rop
. The precision of the result will be set to the largest precision among the operands. Return
a reference to
rop
. Parameters
rop
: the return value.a
: the first operand.b
: the second operand.

template<CvrReal
T
, CvrRealU
>
real &mppp
::
div
(real &rop, T &&a, U &&b)¶ Ternary real division.
This function will compute \(a / b\), storing the result in
rop
. The precision of the result will be set to the largest precision among the operands. Return
a reference to
rop
. Parameters
rop
: the return value.a
: the first operand.b
: the second operand.

template<CvrReal
T
, CvrRealU
, CvrRealV
>
real &mppp
::
fma
(real &rop, T &&a, U &&b, V &&c)¶ Quaternary real fused multiply–add.
This function will compute \(a \times b + c\), storing the result in
rop
. The precision of the result will be set to the largest precision among the operands. Return
a reference to
rop
. Parameters
rop
: the return value.a
: the first operand.b
: the second operand.c
: the third operand.

template<CvrReal
T
, CvrRealU
, CvrRealV
>
realmppp
::
fma
(T &&a, U &&b, V &&c)¶ Ternary real fused multiply–add.
This function will compute and return \(a \times b + c\). The precision of the result will be set to the largest precision among the operands.
 Return
\( a \times b + c \).
 Parameters
a
: the first operand.b
: the second operand.c
: the third operand.

template<CvrReal
T
, CvrRealU
, CvrRealV
>
real &mppp
::
fms
(real &rop, T &&a, U &&b, V &&c)¶ Quaternary real fused multiply–sub.
This function will compute \(a \times b  c\), storing the result in
rop
. The precision of the result will be set to the largest precision among the operands. Return
a reference to
rop
. Parameters
rop
: the return value.a
: the first operand.b
: the second operand.c
: the third operand.

template<CvrReal
T
, CvrRealU
, CvrRealV
>
realmppp
::
fms
(T &&a, U &&b, V &&c)¶ Ternary real fused multiply–sub.
This function will compute and return \(a \times b  c\). The precision of the result will be set to the largest precision among the operands.
 Return
\( a \times b  c \).
 Parameters
a
: the first operand.b
: the second operand.c
: the third operand.

template<CvrReal
T
>
realmppp
::
neg
(T &&x)¶ Unary negation for real.
 Return
the negative of
x
. Parameters
x
: the real that will be negated.

template<CvrReal
T
>
realmppp
::
neg
(real &rop, T &&x)¶ Binary negation for real.
This function will set
rop
to the negation ofx
.
Comparison¶

bool
mppp
::
nan_p
(const real &r)¶ Detect if a real is NaN.
 Return
true
ifr
is NaN,false
otherwise. Parameters
r
: the real that will be examined.

bool
mppp
::
inf_p
(const real &r)¶ Detect if a real is infinity.
 Return
true
ifr
is an infinity,false
otherwise. Parameters
r
: the real that will be examined.

bool
mppp
::
number_p
(const real &r)¶ Detect if real is a finite number.
 Return
true
ifr
is a finite number (i.e., not NaN or infinity),false
otherwise. Parameters
r
: the real that will be examined.

bool
mppp
::
zero_p
(const real &r)¶ Detect if a real is zero.
 Return
true
ifr
is zero,false
otherwise. Parameters
r
: the real that will be examined.

bool
mppp
::
regular_p
(const real &r)¶ Detect if a real is a regular number.
 Return
true
ifr
is a regular number (i.e., not NaN, infinity or zero),false
otherwise. Parameters
r
: the real that will be examined.

bool
mppp
::
is_one
(const real &r)¶ Detect if a real is one.
 Return
true
ifr
is exactly 1,false
otherwise. Parameters
r
: the real to be checked.

int
mppp
::
sgn
(const real &r)¶ Detect the sign of a real.
 Return
a positive value if
r
is positive, zero ifr
is zero, a negative value ifthis
is negative. Parameters
r
: the real that will be examined.
 Exceptions
unspecified
: any exception thrown by mppp::real::sgn().

bool
mppp
::
signbit
(const real &r)¶ Get the sign bit of a real.
The sign bit is set if
r
is negative, 0, or a NaN whose representation has its sign bit set. Return
the sign bit of
r
. Parameters
r
: the real that will be examined.

int
mppp
::
cmp
(const real &a, const real &b)¶ Real comparison.
This function will compare
a
andb
, returning:zero if
a
equalsb
,a negative value if
a
is less thanb
,a positive value if
a
is greater thanb
.
If at least one NaN value is involved in the comparison, an error will be raised.
This function is useful to distinguish the three possible cases. The comparison operators are recommended instead if it is needed to distinguish only two cases.
 Return
an integral value expressing how
a
compares tob
. Parameters
a
: the first operand.b
: the second operand.
 Exceptions
std::domain_error
: if at least one of the operands is NaN.

bool
mppp
::
real_equal_to
(const real &a, const real &b)¶ Equality predicate with special NaN handling for real.
If both
a
andb
are not NaN, this function is identical to the equality operator forreal
. If at least one operand is NaN, this function will returntrue
if both operands are NaN,false
otherwise.In other words, this function behaves like an equality operator which considers all NaN values equal to each other.
 Return
true
if \( a = b \) (including the case in which both operands are NaN),false
otherwise. Parameters
a
: the first operand.b
: the second operand.

bool
mppp
::
real_lt
(const real &a, const real &b)¶ Lessthan predicate with special NaN and movedfrom handling for real.
This function behaves like a lessthan operator which considers NaN values greater than nonNaN values, and movedfrom objects greater than both NaN and nonNaN values. This function can be used as a comparator in various facilities of the standard library (e.g.,
std::sort()
,std::set
, etc.). Return
true
if \( a < b \) (following the rules above regarding NaN values and movedfrom objects),false
otherwise. Parameters
a
: the first operand.b
: the second operand.

bool
mppp
::
real_gt
(const real &a, const real &b)¶ Greaterthan predicate with special NaN and movedfrom handling for real.
This function behaves like a greaterthan operator which considers NaN values greater than nonNaN values, and movedfrom objects greater than both NaN and nonNaN values. This function can be used as a comparator in various facilities of the standard library (e.g.,
std::sort()
,std::set
, etc.). Return
true
if \( a > b \) (following the rules above regarding NaN values and movedfrom objects),false
otherwise. Parameters
a
: the first operand.b
: the second operand.
Roots¶

template<mppp::CvrReal
T
>
mppp::real &mppp
::
sqrt
(mppp::real &rop, T &&op)¶ Binary
real
square root.This function will compute the square root of op and store it into rop. The precision of the result will be equal to the precision of op.
If op is 0, rop will be set to 0. If op is negative, rop will be set to NaN.
 Parameters
rop – the return value.
op – the operand.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
sqrt
(T &&r)¶ Unary
real
square root.This function will compute and return the square root of r. The precision of the result will be equal to the precision of r.
If r is 0, the result will be 0. If r is negative, the result will be NaN.
 Parameters
r – the operand.
 Returns
the square root of r.

template<mppp::CvrReal
T
>
mppp::real &mppp
::
rec_sqrt
(mppp::real &rop, T &&op)¶ New in version 0.12.
Binary
real
reciprocal square root.This function will compute the reciprocal square root of op and store it into rop. The precision of the result will be equal to the precision of op.
If op is zero, rop will be set to a positive infinity (regardless of the sign of op). If op is a positive infinity, rop will be set to +0. If op is negative, rop will be set to NaN.
 Parameters
rop – the return value.
op – the operand.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
rec_sqrt
(T &&r)¶ New in version 0.12.
Unary
real
reciprocal square root.This function will compute and return the reciprocal square root of r. The precision of the result will be equal to the precision of r.
If r is zero, a positive infinity will be returned (regardless of the sign of r). If r is a positive infinity, +0 will be returned. If r is negative, NaN will be returned.
 Parameters
r – the operand.
 Returns
the reciprocal square root of r.

template<mppp::CvrReal
T
>
mppp::real &mppp
::
cbrt
(mppp::real &rop, T &&op)¶ New in version 0.12.
Binary
real
cubic root.This function will compute the cubic root of op and store it into rop. The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the operand.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
cbrt
(T &&r)¶ New in version 0.12.
Unary
real
cubic root.This function will compute and return the cubic root of r. The precision of the result will be equal to the precision of r.
 Parameters
r – the operand.
 Returns
the cubic root of r.

template<mppp::CvrReal
T
>
mppp::real &mppp
::
rootn_ui
(mppp::real &rop, T &&op, unsigned long k)¶ New in version 0.12.
Binary
real
kth root.This function will compute the kth root of op and store it into rop. The precision of the result will be equal to the precision of op.
If k is zero, the result will be NaN. If k is odd (resp. even) and op negative (including negative infinity), the result will be a negative number (resp. NaN). If op is zero, the result will be zero with the sign obtained by the usual limit rules, i.e., the same sign as op if k is odd, and positive if k is even.
Note
This function is available from MPFR 4 onwards.
 Parameters
rop – the return value.
op – the operand.
k – the degree of the root.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
rootn_ui
(T &&r, unsigned long k)¶ New in version 0.12.
Unary
real
kth root.This function will compute and return the kth root of r. The precision of the result will be equal to the precision of r.
If k is zero, the result will be NaN. If k is odd (resp. even) and r negative (including negative infinity), the result will be a negative number (resp. NaN). If r is zero, the result will be zero with the sign obtained by the usual limit rules, i.e., the same sign as r if k is odd, and positive if k is even.
Note
This function is available from MPFR 4 onwards.
 Parameters
r – the operand.
k – the degree of the root.
 Returns
the kth root of r.
Exponentiation¶

template<CvrReal
T
, CvrRealU
>
real &mppp
::
pow
(real &rop, T &&op1, U &&op2)¶ Ternary real exponentiation.
This function will set
rop
toop1
raised to the power ofop2
. The precision ofrop
will be set to the largest precision among the operands. Return
a reference to
rop
. Parameters
rop
: the return value.op1
: the base.op2
: the exponent.

template<typename T, typename U>requires RealOpTypes<T, U> real mppp::pow(T && op1, U && op2)
Binary real exponentiation.
The precision of the result will be set to the largest precision among the operands.
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted. Return
op1
raised to the power ofop2
. Parameters
op1
: the base.op2
: the exponent.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.
Trigonometry¶

template<mppp::CvrReal
T
>
mppp::real &mppp
::
cot
(mppp::real &rop, T &&op)¶ Binary basic trigonometric functions.
These functions will set rop to, respectively, the sine, cosine, tangent, secant, cosecant and cotangent of op. The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the argument.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
cot
(T &&r)¶ Unary basic trigonometric functions.
These functions will return, respectively, the sine, cosine, tangent, secant, cosecant and cotangent of r. The precision of the result will be equal to the precision of r.
 Parameters
r – the argument.
 Returns
the sine, cosine, tangent, secant, cosecant or cotangent of r.

template<mppp::CvrReal
T
>
voidmppp
::
sin_cos
(mppp::real &sop, mppp::real &cop, T &&op)¶ Simultaneous sine and cosine.
This function will set sop and cop respectively to the sine and cosine of op. sop and cop must be distinct objects. The precision of sop and rop will be set to the precision of op.
 Parameters
sop – the sine return value.
cop – the cosine return value.
op – the operand.
 Throws
std::invalid_argument – if sop and cop are the same object.

template<mppp::CvrReal
T
>
mppp::real &mppp
::
atan
(mppp::real &rop, T &&op)¶ Binary basic inverse trigonometric functions.
These functions will set rop to, respectively, the arcsine, arccosine and arctangent of op. The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the argument.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
atan
(T &&r)¶ Unary basic inverse trigonometric functions.
These functions will return, respectively, the arcsine, arccosine and arctangent of r. The precision of the result will be equal to the precision of r.
 Parameters
r – the argument.
 Returns
the arcsine, arccosine or arctangent of r.

template<mppp::CvrReal
T
, mppp::CvrRealU
>
mppp::real &mppp
::
atan2
(mppp::real &rop, T &&y, U &&x)¶ Ternary arctangent2.
This function will set rop to the arctangent2 of y and x. The precision of rop will be set to the largest precision among the operands.
 Parameters
rop – the return value.
y – the sine argument.
x – the cosine argument.
 Returns
a reference to rop.

template<typename
T
, mppp::RealOpTypes<T>U
>
mppp::realmppp
::
atan2
(T &&y, U &&x)¶ Binary arctangent2.
This function will compute and return the arctangent2 of y and x.
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted. Parameters
y – the sine argument.
x – the cosine argument.
 Returns
the arctangent2 of y and x.
 Throws
unspecified – any exception thrown by the generic assignment operator of
real
.
Hyperbolic functions¶

template<mppp::CvrReal
T
>
mppp::real &mppp
::
coth
(mppp::real &rop, T &&op)¶ Binary basic hyperbolic functions.
These functions will set rop to, respectively, the hyperbolic sine, cosine, tangent, secant, cosecant and cotangent of op. The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the argument.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
coth
(T &&r)¶ Unary basic hyperbolic functions.
These functions will return, respectively, the hyperbolic sine, cosine, tangent, secant, cosecant and cotangent of r. The precision of the result will be equal to the precision of r.
 Parameters
r – the argument.
 Returns
the hyperbolic sine, cosine, tangent, secant, cosecant or cotangent of r.

template<mppp::CvrReal
T
>
voidmppp
::
sinh_cosh
(mppp::real &sop, mppp::real &cop, T &&op)¶ Simultaneous hyperbolic sine and cosine.
This function will set sop and cop respectively to the hyperbolic sine and cosine of op. sop and cop must be distinct objects. The precision of sop and rop will be set to the precision of op.
 Parameters
sop – the hyperbolic sine return value.
cop – the hyperbolic cosine return value.
op – the operand.
 Throws
std::invalid_argument – if sop and cop are the same object.

template<mppp::CvrReal
T
>
mppp::real &mppp
::
atanh
(mppp::real &rop, T &&op)¶ Binary basic inverse hyperbolic functions.
These functions will set rop to, respectively, the inverse hyperbolic sine, cosine and tangent of op. The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the argument.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
atanh
(T &&r)¶ Unary basic inverse hyperbolic functions.
These functions will return, respectively, the inverse hyperbolic sine, cosine and tangent of r. The precision of the result will be equal to the precision of r.
 Parameters
r – the argument.
 Returns
the inverse hyperbolic sine, cosine or tangent of r.
Logarithms and exponentials¶

template<mppp::CvrReal
T
>
mppp::real &mppp
::
expm1
(mppp::real &rop, T &&op)¶ Binary exponentials.
These functions will set rop to, respectively,
e**op
,2**op
,10**op
,e**op1
.
The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the exponent.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
expm1
(T &&r)¶ Unary exponentials.
These functions will return, respectively,
e**r
,2**r
,10**r
,e**r1
.
The precision of the result will be equal to the precision of r.
 Parameters
r – the exponent.
 Returns
the exponential of r.

template<mppp::CvrReal
T
>
mppp::real &mppp
::
log1p
(mppp::real &rop, T &&op)¶ Binary logarithms.
These functions will set rop to, respectively,
log(op)
,log2(op)
,log10(op)
,log(1+op)
.
The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the operand.
 Returns
a reference to rop.
Gamma functions¶

template<mppp::CvrReal
T
>
mppp::real &mppp
::
digamma
(mppp::real &rop, T &&op)¶ Binary gamma functions.
These functions will set rop to, respectively,
\(\Gamma\left(op\right)\),
\(\ln\Gamma\left(op\right)\),
\(\ln\left\Gamma\left(op\right)\right\),
\(\psi\left(op\right)\).
The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the argument.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
digamma
(T &&r)¶ Unary gamma functions.
These functions will return, respectively,
\(\Gamma\left(r\right)\),
\(\ln\Gamma\left(r\right)\),
\(\ln\left\Gamma\left(r\right)\right\),
\(\psi\left(r\right)\).
The precision of the result will be equal to the precision of r.
 Parameters
r – the argument.
 Returns
the Gamma function, logarithm of the Gamma function, logarithm of the absolute value of the Gamma function, or the Digamma function of r.

template<mppp::CvrReal
T
, mppp::CvrRealU
>
mppp::real &mppp
::
gamma_inc
(mppp::real &rop, T &&x, U &&y)¶ New in version 0.17.
Ternary incomplete Gamma function.
This function will set rop to the upper incomplete Gamma function of x and y. The precision of rop will be set to the largest precision among the operands.
Note
This function is available from MPFR 4 onwards.
 Parameters
rop – the return value.
x – the first argument.
y – the second argument.
 Returns
a reference to rop.

template<typename
T
, mppp::RealOpTypes<T>U
>
mppp::realmppp
::
gamma_inc
(T &&x, U &&y)¶ New in version 0.17.
Binary incomplete Gamma function.
This function will compute and return the upper incomplete Gamma function of x and y.
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted.Note
This function is available from MPFR 4 onwards.
 Parameters
x – the first argument.
y – the second argument.
 Returns
the upper incomplete Gamma function of x and y
 Throws
unspecified – any exception thrown by the generic assignment operator of
real
.
Bessel functions¶
New in version 0.17.

template<mppp::CvrReal
T
>
mppp::real &mppp
::
yn
(mppp::real &rop, long n, T &&op)¶ Bessel functions.
These functions will set rop to, respectively,
the Bessel function of the first kind of order 0 \(\left(J_0\right)\) of op,
the Bessel function of the first kind of order 1 \(\left(J_1\right)\) of op,
the Bessel function of the first kind of order n \(\left(J_n\right)\) of op,
the Bessel function of the second kind of order 0 \(\left(Y_0\right)\) of op,
the Bessel function of the second kind of order 1 \(\left(Y_1\right)\) of op,
the Bessel function of the second kind of order n \(\left(Y_n\right)\) of op.
The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the argument.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
yn
(long n, T &&r)¶ Bessel functions.
These functions will return, respectively,
the Bessel function of the first kind of order 0 \(\left(J_0\right)\) of r,
the Bessel function of the first kind of order 1 \(\left(J_1\right)\) of r,
the Bessel function of the first kind of order n \(\left(J_n\right)\) of r,
the Bessel function of the second kind of order 0 \(\left(Y_0\right)\) of r,
the Bessel function of the second kind of order 1 \(\left(Y_1\right)\) of r,
the Bessel function of the second kind of order n \(\left(Y_n\right)\) of r.
The precision of the result will be equal to the precision of r.
 Parameters
r – the argument.
 Returns
the Bessel function of r.
Error functions¶

template<mppp::CvrReal
T
>
mppp::real &mppp
::
erfc
(mppp::real &rop, T &&op)¶ Binary error functions.
These functions will set rop to, respectively, the error function and the complementary error function of op. The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the argument.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
erfc
(T &&r)¶ Unary error functions.
These functions will return, respectively, the error function and the complementary error function of r. The precision of the result will be equal to the precision of r.
 Parameters
r – the argument.
 Returns
the error function or the complementary error function of r.
Other special functions¶

template<mppp::CvrReal
T
>
mppp::real &mppp
::
ai
(mppp::real &rop, T &&op)¶ Other binary special functions.
These functions will set rop to, respectively,
the exponential integral,
the dilogarithm,
the Riemann Zeta function,
the Airy function,
of op. The precision of the result will be equal to the precision of op.
 Parameters
rop – the return value.
op – the argument.
 Returns
a reference to rop.

template<mppp::CvrReal
T
>
mppp::realmppp
::
ai
(T &&r)¶ Other unary special functions.
These functions will return, respectively,
the exponential integral,
the dilogarithm,
the Riemann Zeta function,
the Airy function,
of r. The precision of the result will be equal to the precision of r.
 Parameters
r – the argument.
 Returns
the exponential integral, dilogarithm, Riemann Zeta function or Airy function of r.

template<mppp::CvrReal
T
, mppp::CvrRealU
>
mppp::real &mppp
::
beta
(mppp::real &rop, T &&x, U &&y)¶ Ternary beta function.
This function will set rop to the beta function of x and y. The precision of rop will be set to the largest precision among the operands.
Note
This function is available from MPFR 4 onwards.
 Parameters
rop – the return value.
x – the first argument.
y – the second argument.
 Returns
a reference to rop.

template<typename
T
, mppp::RealOpTypes<T>U
>
mppp::realmppp
::
beta
(T &&x, U &&y)¶ Binary beta function.
This function will compute and return the beta function of x and y.
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted.Note
This function is available from MPFR 4 onwards.
 Parameters
x – the first argument.
y – the second argument.
 Returns
the beta function of x and y.
 Throws
unspecified – any exception thrown by the generic assignment operator of
real
.

template<mppp::CvrReal
T
, mppp::CvrRealU
>
mppp::real &mppp
::
hypot
(mppp::real &rop, T &&x, U &&y)¶ Ternary hypot function.
This function will set rop to \(\sqrt{x^2+y^2}\). The precision of rop will be set to the largest precision among the operands.
 Parameters
rop – the return value.
x – the first argument.
y – the second argument.
 Returns
a reference to rop.

template<typename
T
, mppp::RealOpTypes<T>U
>
mppp::realmppp
::
hypot
(T &&x, U &&y)¶ Binary hypot function.
This function will compute and return \(\sqrt{x^2+y^2}\).
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted. Parameters
x – the first argument.
y – the second argument.
 Returns
the hypot function of x and y.
 Throws
unspecified – any exception thrown by the generic assignment operator of
real
.

template<mppp::CvrReal
T
, mppp::CvrRealU
>
mppp::real &mppp
::
agm
(mppp::real &rop, T &&x, U &&y)¶ Ternary AGM.
This function will set rop to the arithmeticgeometric mean of x and y. The precision of rop will be set to the largest precision among the operands.
 Parameters
rop – the return value.
x – the first argument.
y – the second argument.
 Returns
a reference to rop.

template<typename
T
, mppp::RealOpTypes<T>U
>
mppp::realmppp
::
agm
(T &&x, U &&y)¶ Binary AGM.
This function will compute and return the arithmeticgeometric mean of x and y.
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted. Parameters
x – the first argument.
y – the second argument.
 Returns
the AGM of x and y.
 Throws
unspecified – any exception thrown by the generic assignment operator of
real
.
Input/Output¶

std::ostream &
mppp
::
operator<<
(std::ostream &os, const real &r)¶ Output stream operator for real objects.
This operator will insert into the stream
os
a string representation ofr
in base 10 (as returned bymppp::real::to_string()
).Warning
In future versions of mp++, the behaviour of this operator will change to support the output stream’s formatting flags. For the time being, users are encouraged to use the
mpfr_get_str()
function from the MPFR library if precise and forwardcompatible control on the printing format is needed. Return
a reference to
os
. Parameters
os
: the target stream.r
: the real that will be directed toos
.
 Exceptions
unspecified
: any exception thrown by mppp::real::to_string().
Mathematical operators¶

template<CvrReal
T
>
realmppp
::
operator+
(T &&r)¶ Identity operator for real.
This operator will return a copy of the input
real
r
. Return
a copy of
r
. Parameters
r
: the real that will be copied.

template<typename T, typename U>requires RealOpTypes<T, U> real mppp::operator+(T && a, U && b)
Binary addition involving real.
The precision of the result will be set to the largest precision among the operands.
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted. Return
\(a+b\).
 Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.

template<typename T, typename U>requires RealCompoundOpTypes<T, U> T& mppp::operator+=(T & a, U && b)
Inplace addition involving real.
If
a
is areal
, then this operator is equivalent to the expression:a = a + b;
Otherwise, this operator is equivalent to the expression:
a = static_cast<T>(a + b);
That is, the operation is always performed via the corresponding binary operator and the result is assigned back to
a
, after a conversion if necessary. Return
a reference to
a
. Parameters
a
: the augend.b
: the addend.
 Exceptions
unspecified
: any exception thrown by the corresponding binary operator, or by the generic conversion operator of real.

real &
mppp
::
operator++
(real &x)¶ Prefix increment for real.
This operator will increment
x
by one. Return
a reference to
x
after the increment. Parameters
x
: the real that will be increased.

real
mppp
::
operator++
(real &x, int)¶ Suffix increment for real.
This operator will increment
x
by one and return a copy ofx
as it was before the increment. Return
a copy of
x
before the increment. Parameters
x
: the real that will be increased.

template<CvrReal
T
>
realmppp
::
operator
(T &&r)¶ Negated copy for real.
This operator will return a negated copy of the input
real
r
. Return
a negated copy of
r
. Parameters
r
: the real that will be negated.

template<typename T, typename U>requires RealOpTypes<T, U> real mppp::operator(T && a, U && b)
Binary subtraction involving real.
The precision of the result will be set to the largest precision among the operands.
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted. Return
\(ab\).
 Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.

template<typename T, typename U>requires RealCompoundOpTypes<T, U> T& mppp::operator=(T & a, U && b)
Inplace subtraction involving real.
If
a
is areal
, then this operator is equivalent to the expression:a = a  b;
Otherwise, this operator is equivalent to the expression:
a = static_cast<T>(a  b);
That is, the operation is always performed via the corresponding binary operator and the result is assigned back to
a
, after a conversion if necessary. Return
a reference to
a
. Parameters
a
: the minuend.b
: the subtrahend.
 Exceptions
unspecified
: any exception thrown by the corresponding binary operator, or by the generic conversion operator of real.

real &
mppp
::
operator
(real &x)¶ Prefix decrement for real.
This operator will decrement
x
by one. Return
a reference to
x
after the decrement. Parameters
x
: the real that will be decreased.

real
mppp
::
operator
(real &x, int)¶ Suffix decrement for real.
This operator will decrement
x
by one and return a copy ofx
as it was before the decrement. Return
a copy of
x
before the decrement. Parameters
x
: the real that will be decreased.

template<typename T, typename U>requires RealOpTypes<T, U> real mppp::operator*(T && a, U && b)
Binary multiplication involving real.
The precision of the result will be set to the largest precision among the operands.
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted. Return
\(a\times b\).
 Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.

template<typename T, typename U>requires RealCompoundOpTypes<T, U> T& mppp::operator*=(T & a, U && b)
Inplace multiplication involving real.
If
a
is areal
, then this operator is equivalent to the expression:a = a * b;
Otherwise, this operator is equivalent to the expression:
a = static_cast<T>(a * b);
That is, the operation is always performed via the corresponding binary operator and the result is assigned back to
a
, after a conversion if necessary. Return
a reference to
a
. Parameters
a
: the multiplicand.b
: the multiplicator.
 Exceptions
unspecified
: any exception thrown by the corresponding binary operator, or by the generic conversion operator of real.

template<typename
U
, RealOpTypes<U>T
>
realmppp
::
operator/
(T &&a, U &&b)¶ Binary division involving real.
The precision of the result will be set to the largest precision among the operands.
Non
real
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted. Return
\(a / b\).
 Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.

template<typename T, typename U>requires RealCompoundOpTypes<T, U> T& mppp::operator/=(T & a, U && b)
Inplace division involving real.
If
a
is areal
, then this operator is equivalent to the expression:a = a / b;
Otherwise, this operator is equivalent to the expression:
a = static_cast<T>(a / b);
That is, the operation is always performed via the corresponding binary operator and the result is assigned back to
a
, after a conversion if necessary. Return
a reference to
a
. Parameters
a
: the dividend.b
: the divisor.
 Exceptions
unspecified
: any exception thrown by the corresponding binary operator, or by the generic conversion operator of real.

template<typename T, typename U>requires RealOpTypes<T, U> bool mppp::operator==(const T & a, const U & b)
Equality operator involving real.
This operator will compare
a
andb
, returningtrue
ifa
is equal tob
,false
otherwise. The comparison is performed via thempfr_equal_p()
function from the MPFR API. Nonreal
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted.Note
This operator does not handle NaN in a special way (that is, NaN compares different from any value, including NaN itself). See
mppp::real_equal_to()
for an equality predicate that handles NaN specially. Return
true
ifa
is equal tob
,false
otherwise. Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.

template<typename T, typename U>requires RealOpTypes<T, U> bool mppp::operator!=(const T & a, const U & b)
Inequality operator involving real.
This operator will compare
a
andb
, returningtrue
ifa
is different fromb
,false
otherwise. The comparison is performed via thempfr_equal_p()
function from the MPFR API. Nonreal
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted.Note
This operator does not handle NaN in a special way (that is, NaN compares different from any value, including NaN itself). See
mppp::real_equal_to()
for an equality predicate that handles NaN specially. Return
true
ifa
is different fromb
,false
otherwise. Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.

template<typename T, typename U>requires RealOpTypes<T, U> bool mppp::operator>(const T & a, const U & b)
Greaterthan operator involving real.
This operator will compare
a
andb
, returningtrue
ifa
is greater thanb
,false
otherwise. The comparison is performed via thempfr_greater_p()
function from the MPFR API. Nonreal
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted.Note
This operator does not handle NaN in a special way (that is, NaN is never greater than any value, and no value is greater than NaN). See
mppp::real_gt()
for a greaterthan predicate that handles NaN specially. Return
true
ifa
is greater thanb
,false
otherwise. Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.

template<typename T, typename U>requires RealOpTypes<T, U> bool mppp::operator>=(const T & a, const U & b)
Greaterthan or equal operator involving real.
This operator will compare
a
andb
, returningtrue
ifa
is greater than or equal tob
,false
otherwise. The comparison is performed via thempfr_greaterequal_p()
function from the MPFR API. Nonreal
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted.Note
This operator does not handle NaN in a special way (that is, NaN is never greater than or equal to any value, and no value is greater than or equal to NaN).
 Return
true
ifa
is greater than or equal tob
,false
otherwise. Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.

template<typename T, typename U>requires RealOpTypes<T, U> bool mppp::operator<(const T & a, const U & b)
Lessthan operator involving real.
This operator will compare
a
andb
, returningtrue
ifa
is less thanb
,false
otherwise. The comparison is performed via thempfr_less_p()
function from the MPFR API. Nonreal
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted.Note
This operator does not handle NaN in a special way (that is, NaN is never less than any value, and no value is less than NaN). See
mppp::real_lt()
for a lessthan predicate that handles NaN specially. Return
true
ifa
is less thanb
,false
otherwise. Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.

template<typename T, typename U>requires RealOpTypes<T, U> bool mppp::operator<=(const T & a, const U & b)
Lessthan or equal operator involving real.
This operator will compare
a
andb
, returningtrue
ifa
is less than or equal tob
,false
otherwise. The comparison is performed via thempfr_lessequal_p()
function from the MPFR API. Nonreal
operands will be converted toreal
before performing the operation. The conversion of nonreal
operands toreal
follows the same heuristics described in the generic assignment operator ofreal
. Specifically, the precision of the conversion is either the default precision, if set, or it is automatically deduced depending on the type and value of the operand to be converted.Note
This operator does not handle NaN in a special way (that is, NaN is never less than or equal to any value, and no value is less than or equal to NaN).
 Return
true
ifa
is less than or equal tob
,false
otherwise. Parameters
a
: the first operand.b
: the second operand.
 Exceptions
unspecified
: any exception thrown by the generic assignment operator of real.
Constants¶

real
mppp
::
real_pi
(mpfr_prec_t p = 0)¶ Real \(\pi\) constant.
This function will return a
real
\(\pi\) with a precision ofp
. Ifp
is zero, the precision will be set to the value returned byreal_get_default_prec()
. Ifp
is zero and no default precision has been set, an error will be raised. Return
a real \(\pi\).
 Parameters
p
: the desired precision.
 Exceptions
std::invalid_argument
: ifp
is not within the bounds established by real_prec_min() and real_prec_max(), or ifp
is zero but no default precision has been set.