piranha  0.10
piranha::real Class Reference

Arbitrary precision floating-point class. More...

#include <piranha/real.hpp>

Inherits real_base<>.

## Public Member Functions

real ()
Default constructor. More...

real (const real &other)
Copy constructor. More...

real (real &&other) noexcept
Move constructor. More...

real (const char *str, const ::mpfr_prec_t &prec=default_prec)
Constructor from C string. More...

real (const std::string &str, const ::mpfr_prec_t &prec=default_prec)
Constructor from C++ string. More...

real (const real &other, const ::mpfr_prec_t &prec)
Copy constructor with different precision. More...

template<typename T , typename = generic_ctor_enabler<T>>
real (const T &x, const ::mpfr_prec_t &prec=default_prec)
Generic constructor. More...

~real ()
Destructor. More...

realoperator= (const real &other)
Copy assignment operator. More...

realoperator= (real &&other) noexcept
Move assignment operator. More...

realoperator= (const std::string &str)
Assignment operator from C++ string. More...

realoperator= (const char *str)
Assignment operator from C string. More...

template<typename T , typename = generic_ctor_enabler<T>>
realoperator= (const T &x)
Generic assignment operator. More...

template<typename T , typename = cast_enabler<T>>
operator T () const
Conversion operator. More...

void swap (real &other)
Swap. More...

int sign () const
Sign. More...

bool is_zero () const
Test for zero. More...

bool is_nan () const
Test for NaN. More...

bool is_inf () const
Test for infinity. More...

::mpfr_prec_t get_prec () const
Get precision. More...

void set_prec (const ::mpfr_prec_t &prec)
Set precision. More...

void negate ()
Negate in-place. More...

void truncate ()
Truncate in-place. More...

real truncated () const
Truncated copy. More...

template<typename T >
auto operator+= (const T &x) -> decltype(this->in_place_add(x))

real operator+ () const
Identity operator. More...

realoperator++ ()
Prefix increment. More...

real operator++ (int)
Suffix increment. More...

template<typename T >
auto operator-= (const T &x) -> decltype(this->in_place_sub(x))
In-place subtraction. More...

real operator- () const
Negated copy. More...

realoperator-- ()
Prefix decrement. More...

real operator-- (int)
Suffix decrement. More...

template<typename T >
auto operator*= (const T &x) -> decltype(this->in_place_mul(x))
In-place multiplication. More...

template<typename T >
auto operator/= (const T &x) -> decltype(this->in_place_div(x))
In-place division. More...

realmultiply_accumulate (const real &r1, const real &r2)

real pow (const real &exp) const
Exponentiation. More...

real gamma () const
Gamma function. More...

real lgamma () const
Logarithm of the gamma function. More...

real exp () const
Exponential. More...

real binomial (const real &) const
Binomial coefficient. More...

real abs () const
Absolute value. More...

real sin () const
Sine. More...

real cos () const
Cosine. More...

real pi () const
Pi constant. More...

template<typename Stream , msgpack_pack_enabler< Stream > = 0>
void msgpack_pack (msgpack::packer< Stream > &p, msgpack_format f) const
Pack in msgpack format. More...

template<typename U = real, msgpack_convert_enabler< U > = 0>
void msgpack_convert (const msgpack::object &o, msgpack_format f)
Convert from msgpack object. More...

Low-level interface

Low-level methods. These methods allow direct access to the internal MPFR instance.

std::remove_extent<::mpfr_t >::type * get_mpfr_t ()
Get a mutable reference to the internal mpfr_t instance.

const std::remove_extent<::mpfr_t >::type * get_mpfr_t () const
Get a const reference to the internal mpfr_t instance.

## Friends

template<typename T , generic_in_place_enabler< T > = 0>
T & operator+= (T &x, const real &r)
Generic in-place addition with piranha::real. More...

template<typename T , typename U >
auto operator+ (const T &x, const U &y) -> decltype(real::binary_add(x, y))
Generic binary addition involving piranha::real. More...

template<typename T , generic_in_place_enabler< T > = 0>
T & operator-= (T &x, const real &r)
Generic in-place subtraction with piranha::real. More...

template<typename T , typename U >
auto operator- (const T &x, const U &y) -> decltype(real::binary_sub(x, y))
Generic binary subtraction involving piranha::real. More...

template<typename T , generic_in_place_enabler< T > = 0>
T & operator*= (T &x, const real &r)
Generic in-place multiplication by piranha::real. More...

template<typename T , typename U >
auto operator* (const T &x, const U &y) -> decltype(real::binary_mul(x, y))
Generic binary multiplication involving piranha::real. More...

template<typename T , generic_in_place_enabler< T > = 0>
T & operator/= (T &x, const real &r)
Generic in-place division by piranha::real. More...

template<typename T , typename U >
auto operator/ (const T &x, const U &y) -> decltype(real::binary_div(x, y))
Generic binary division involving piranha::real. More...

template<typename T , typename U >
auto operator== (const T &x, const U &y) -> decltype(real::binary_equality(x, y))
Generic equality operator involving piranha::real. More...

template<typename T , typename U >
auto operator!= (const T &x, const U &y) -> decltype(!real::binary_equality(x, y))
Generic inequality operator involving piranha::real. More...

template<typename T , typename U >
auto operator< (const T &x, const U &y) -> decltype(real::binary_less_than(x, y))
Generic less-than operator involving piranha::real. More...

template<typename T , typename U >
auto operator<= (const T &x, const U &y) -> decltype(real::binary_leq(x, y))
Generic less-than or equal operator involving piranha::real. More...

template<typename T , typename U >
auto operator> (const T &x, const U &y) -> decltype(real::binary_less_than(y, x))
Generic greater-than operator involving piranha::real. More...

template<typename T , typename U >
auto operator>= (const T &x, const U &y) -> decltype(real::binary_leq(y, x))
Generic greater-than or equal operator involving piranha::real. More...

std::ostream & operator<< (std::ostream &os, const real &r)
Overload output stream operator for piranha::real. More...

std::istream & operator>> (std::istream &is, real &r)
Overload input stream operator for piranha::real. More...

## Detailed Description

Arbitrary precision floating-point class.

This class represents floating-point ("real") numbers of arbitrary size (i.e., the size is limited only by the available memory). The implementation consists of a C++ wrapper around the mpfr_t type from the multiprecision MPFR library. Real numbers are represented in binary format and they consist of an arbitrary-size significand coupled to a fixed-size exponent.

Unless noted otherwise, this implementation always uses the MPFR_RNDN (round to nearest) rounding mode for all operations.

## Interoperability with other types

This class interoperates with the same types as piranha::mp_integer and piranha::mp_rational, plus piranha::mp_integer and piranha::mp_rational themselves.

## Exception safety guarantee

Unless noted otherwise, this class provides the strong exception safety guarantee for all operations. In case of memory allocation errors by GMP/MPFR routines, the program will terminate.

## Move semantics

Move construction and move assignment will leave the moved-from object in a state that is destructible and assignable.

Definition at line 126 of file real.hpp.

## ◆ real() [1/7]

 piranha::real::real ( )
inline

Default constructor.

Will initialize the number to zero, using real::default_prec as significand precision.

Definition at line 740 of file real.hpp.

## ◆ real() [2/7]

 piranha::real::real ( const real & other )
inline

Copy constructor.

Will deep-copy other.

Parameters
 other real to be copied.

Definition at line 751 of file real.hpp.

## ◆ real() [3/7]

 piranha::real::real ( real && other )
inlinenoexcept

Move constructor.

Parameters
 other real to be moved.

Definition at line 761 of file real.hpp.

## ◆ real() [4/7]

 piranha::real::real ( const char * str, const ::mpfr_prec_t & prec = default_prec )
inlineexplicit

Constructor from C string.

Will use the string str and precision prec to initialize the number. The expected string format, assuming representation in base 10, is described in the MPFR documentation.

Parameters
 str string representation of the real number. prec desired significand precision.
Exceptions
 std::invalid_argument if the conversion from string fails or if the requested significand precision is not within the range allowed by the MPFR library.

Definition at line 784 of file real.hpp.

## ◆ real() [5/7]

 piranha::real::real ( const std::string & str, const ::mpfr_prec_t & prec = default_prec )
inlineexplicit

Constructor from C++ string.

Equivalent to the constructor from C string.

Parameters
 str string representation of the real number. prec desired significand precision.
Exceptions
 unspecified any exception thrown by the constructor from C string.

Definition at line 797 of file real.hpp.

## ◆ real() [6/7]

 piranha::real::real ( const real & other, const ::mpfr_prec_t & prec )
inlineexplicit

Copy constructor with different precision.

this will be first initialised with precision prec, and then other will be assigned to this.

Parameters
 other real to be copied. prec desired significand precision.
Exceptions
 std::invalid_argument if the requested significand precision is not within the range allowed by the MPFR library.

Definition at line 811 of file real.hpp.

## ◆ real() [7/7]

template<typename T , typename = generic_ctor_enabler<T>>
 piranha::real::real ( const T & x, const ::mpfr_prec_t & prec = default_prec )
inlineexplicit

Generic constructor.

Note
This constructor is enabled only if T is an interoperable type.
Parameters
 x object used to construct this. prec desired significand precision.
Exceptions
 std::invalid_argument if the requested significand precision is not within the range allowed by the MPFR library.

Definition at line 829 of file real.hpp.

## ◆ ~real()

 piranha::real::~real ( )
inline

Destructor.

Will clear the internal MPFR variable.

Definition at line 2143 of file real.hpp.

## ◆ abs()

 real piranha::real::abs ( ) const
inline

Absolute value.

Returns
absolute value of this.

Definition at line 1618 of file real.hpp.

## ◆ binomial()

 real piranha::real::binomial ( const real & y ) const
inline

Binomial coefficient.

This method will return this choose y. Any combination of real values is supported. The implementation uses the logarithm of the gamma function, thus the result will not be in general exact (even if this and y are integral values).

The returned value will have the maximum precision between this and y.

Parameters
 y bottom value.
Returns
this choose y.
Exceptions
 std::invalid_argument if either this or y is not finite. unspecified any exception resulting from arithmetic operations on piranha::real.

Definition at line 2214 of file real.hpp.

## ◆ cos()

 real piranha::real::cos ( ) const
inline

Cosine.

Returns
cosine of this, computed with the precision of this.

Definition at line 1638 of file real.hpp.

## ◆ exp()

 real piranha::real::exp ( ) const
inline

Exponential.

Returns
the exponential of this.

Definition at line 1607 of file real.hpp.

## ◆ gamma()

 real piranha::real::gamma ( ) const
inline

Gamma function.

Returns
gamma of this.

Definition at line 1585 of file real.hpp.

## ◆ get_prec()

 ::mpfr_prec_t piranha::real::get_prec ( ) const
inline

Get precision.

Returns
the number of bits used to represent the significand of this.

Definition at line 1024 of file real.hpp.

## ◆ is_inf()

 bool piranha::real::is_inf ( ) const
inline

Test for infinity.

Returns
true if this represents infinity, false otherwise.

Definition at line 1016 of file real.hpp.

## ◆ is_nan()

 bool piranha::real::is_nan ( ) const
inline

Test for NaN.

Returns
true if this is NaN, false otherwise.

Definition at line 1008 of file real.hpp.

## ◆ is_zero()

 bool piranha::real::is_zero ( ) const
inline

Test for zero.

Returns
true it this is zero, false otherwise.

Definition at line 1000 of file real.hpp.

## ◆ lgamma()

 real piranha::real::lgamma ( ) const
inline

Logarithm of the gamma function.

Returns
logarithm of the absolute value of the gamma of this.

Definition at line 1595 of file real.hpp.

## ◆ msgpack_convert()

template<typename U = real, msgpack_convert_enabler< U > = 0>
 void piranha::real::msgpack_convert ( const msgpack::object & o, msgpack_format f )
inline

Convert from msgpack object.

Note
This method is enabled only if std::string and all the integral types used to define the internal representation of piranha::real satisfy piranha::has_msgpack_convert.

This method will convert the object o into this. If f is piranha::msgpack_format::binary, this method offers the basic exception safety guarantee and it performs minimal checking on the input data. Calling this method in binary mode will result in undefined behaviour if o does not contain an integer serialized via msgpack_pack().

Parameters
 o source object. f the desired piranha::msgpack_format.
Exceptions
 std::invalid_argument if, in binary mode, the number of serialized limbs is inconsistent with the precision. unspecified any exception thrown by: piranha::safe_cast(), set_prec(), memory errors in standard containers, the public interface of msgpack::object, piranha::msgpack_convert(), the constructor of piranha::real from string.

Definition at line 1841 of file real.hpp.

## ◆ msgpack_pack()

template<typename Stream , msgpack_pack_enabler< Stream > = 0>
 void piranha::real::msgpack_pack ( msgpack::packer< Stream > & p, msgpack_format f ) const
inline

Pack in msgpack format.

Note
This method is enabled only if:

This method will pack this into p. If f is msgpack_format::portable, then the precision of this and a decimal string representation of this are packed in an array. Otherwise, an array of 4 elements storing the internal MPFR representation of this is packed.

Parameters
 p target msgpack::packer. f the desired piranha::msgpack_format.
Exceptions
 unspecified any exception thrown by: piranha::safe_cast(), the public interface of msgpack::packer, piranha::msgpack_pack(), the conversion of this to string.

Definition at line 1790 of file real.hpp.

## ◆ multiply_accumulate()

 real& piranha::real::multiply_accumulate ( const real & r1, const real & r2 )
inline

Sets this to this + (r1 * r2). If the precision of this is less than the maximum precision max_prec of the two operands r1 and r2, the precision of this will be set to max_prec before performing the operation.

Parameters
 r1 first argument. r2 second argument.
Returns
reference to this.

Definition at line 1402 of file real.hpp.

## ◆ negate()

 void piranha::real::negate ( )
inline

Negate in-place.

Will set this to -this.

Definition at line 1046 of file real.hpp.

## ◆ operator T()

template<typename T , typename = cast_enabler<T>>
 piranha::real::operator T ( ) const
inlineexplicit

Conversion operator.

Note
This operator is enabled only if T is an interoperable type.

Extract an instance of type T from this.

Conversion to bool is always successful, and returns sign() != 0. Conversion to the other integral types is truncated (i.e., rounded to zero), its success depending on whether or not the target type can represent the truncated value.

Conversion to floating point types is exact if the target type can represent exactly the current value. If that is not the case, the output value will be the nearest adjacent. If this is not finite, corresponding non-finite values will be produced if the floating-point type supports them, otherwise an error will be produced.

Conversion of finite values to piranha::mp_rational will be exact. Conversion of non-finite values will result in runtime errors.

Returns
result of the conversion to target type T.
Exceptions
 std::overflow_error if the conversion fails in one of the ways described above.

Definition at line 966 of file real.hpp.

## ◆ operator*=()

template<typename T >
 auto piranha::real::operator*= ( const T & x ) -> decltype(this->in_place_mul(x))
inline

In-place multiplication.

Note
This operator is enabled only if T is an interoperable type or piranha::real.

Multiply by x the current value of the real object.

If the precision prec of x is greater than the precision of this, the precision of this is changed to prec before the operation takes place.

Parameters
 x argument for the multiplication.
Returns
reference to this.
Exceptions
 unspecified any exception thrown by the contructor of piranha::mp_integer, if invoked.

Definition at line 1280 of file real.hpp.

## ◆ operator+()

 real piranha::real::operator+ ( ) const
inline

Identity operator.

Returns
copy of this.

Definition at line 1141 of file real.hpp.

## ◆ operator++() [1/2]

 real& piranha::real::operator++ ( )
inline

Prefix increment.

Increment this by one.

Returns
reference to this after the increment.

Definition at line 1151 of file real.hpp.

## ◆ operator++() [2/2]

 real piranha::real::operator++ ( int )
inline

Suffix increment.

Increment this by one and return a copy of this as it was before the increment.

Returns
copy of this before the increment.

Definition at line 1161 of file real.hpp.

## ◆ operator+=()

template<typename T >
 auto piranha::real::operator+= ( const T & x ) -> decltype(this->in_place_add(x))
inline

Note
This operator is enabled only if T is an interoperable type or piranha::real.

Add x to the current value of the real object.

If the precision prec of x is greater than the precision of this, the precision of this is changed to prec before the operation takes place.

Parameters
Returns
reference to this.
Exceptions
 unspecified any exception thrown by the contructor of piranha::mp_integer, if invoked.

Definition at line 1089 of file real.hpp.

## ◆ operator-()

 real piranha::real::operator- ( ) const
inline

Negated copy.

Returns
copy of -this.

Definition at line 1235 of file real.hpp.

## ◆ operator--() [1/2]

 real& piranha::real::operator-- ( )
inline

Prefix decrement.

Decrement this by one and return.

Returns
reference to this.

Definition at line 1247 of file real.hpp.

## ◆ operator--() [2/2]

 real piranha::real::operator-- ( int )
inline

Suffix decrement.

Decrement this by one and return a copy of this as it was before the decrement.

Returns
copy of this before the decrement.

Definition at line 1257 of file real.hpp.

## ◆ operator-=()

template<typename T >
 auto piranha::real::operator-= ( const T & x ) -> decltype(this->in_place_sub(x))
inline

In-place subtraction.

Note
This operator is enabled only if T is an interoperable type or piranha::real.

Subtract x from the current value of the real object.

If the precision prec of x is greater than the precision of this, the precision of this is changed to prec before the operation takes place.

Parameters
 x argument for the subtraction.
Returns
reference to this.
Exceptions
 unspecified any exception thrown by the contructor of piranha::mp_integer, if invoked.

Definition at line 1184 of file real.hpp.

## ◆ operator/=()

template<typename T >
 auto piranha::real::operator/= ( const T & x ) -> decltype(this->in_place_div(x))
inline

In-place division.

Note
This operator is enabled only if T is an interoperable type or piranha::real.

Divide by x the current value of the real object.

If the precision prec of x is greater than the precision of this, the precision of this is changed to prec before the operation takes place.

Parameters
 x argument for the division.
Returns
reference to this.
Exceptions
 unspecified any exception thrown by the contructor of piranha::mp_integer, if invoked.

Definition at line 1344 of file real.hpp.

## ◆ operator=() [1/5]

 real& piranha::real::operator= ( const real & other )
inline

Copy assignment operator.

The assignment operation will deep-copy other (i.e., including its precision).

Parameters
 other real to be copied.
Returns
reference to this.

Definition at line 848 of file real.hpp.

## ◆ operator=() [2/5]

 real& piranha::real::operator= ( real && other )
inlinenoexcept

Move assignment operator.

Parameters
 other real to be moved.
Returns
reference to this.

Definition at line 870 of file real.hpp.

## ◆ operator=() [3/5]

 real& piranha::real::operator= ( const std::string & str )
inline

Assignment operator from C++ string.

The implementation is equivalent to the assignment operator from C string.

Parameters
 str string representation of the real to be assigned.
Returns
reference to this.
Exceptions
 unspecified any exception thrown by the assignment operator from C string.

Definition at line 886 of file real.hpp.

## ◆ operator=() [4/5]

 real& piranha::real::operator= ( const char * str )
inline

Assignment operator from C string.

The parsing rules are the same as in the constructor from string. The precision of this will not be changed by the assignment operation, unless this was the target of a move operation that left it in an uninitialised state. In that case, this will be re-initialised with the default precision.

In case str is malformed, before an exception is thrown the value of this will be reset to zero.

Parameters
 str string representation of the real to be assigned.
Returns
reference to this.
Exceptions
 std::invalid_argument if the conversion from string fails.

Definition at line 905 of file real.hpp.

## ◆ operator=() [5/5]

template<typename T , typename = generic_ctor_enabler<T>>
 real& piranha::real::operator= ( const T & x )
inline

Generic assignment operator.

Note
This assignment operator is enabled only if T is an interoperable type.

The precision of this will not be changed by the assignment operation, unless this was the target of a move operation that left it in an uninitialised state. In that case, this will be re-initialised with the default precision.

Parameters
 x object that will be assigned to this.
Returns
reference to this.

Definition at line 931 of file real.hpp.

## ◆ pi()

 real piranha::real::pi ( ) const
inline

Pi constant.

Returns
pi constant calculated to the current precision of this.

Definition at line 1648 of file real.hpp.

## ◆ pow()

 real piranha::real::pow ( const real & exp ) const
inline

Exponentiation.

The operation is carried out with the maximum precision between this and exp.

Parameters
 exp exponent.
Returns
this ** exp.

Definition at line 1572 of file real.hpp.

## ◆ set_prec()

 void piranha::real::set_prec ( const ::mpfr_prec_t & prec )
inline

Set precision.

Will set the significand precision of this to exactly prec bits, and reset the value of this to NaN.

Parameters
 prec desired significand precision.
Exceptions
 std::invalid_argument if the requested significand precision is not within the range allowed by the MPFR library.

Definition at line 1037 of file real.hpp.

## ◆ sign()

 int piranha::real::sign ( ) const
inline

Sign.

Returns
1 if this > 0, 0 if this == 0 and -1 if this < 0. If this is NaN, zero will be returned.

Definition at line 988 of file real.hpp.

## ◆ sin()

 real piranha::real::sin ( ) const
inline

Sine.

Returns
sine of this, computed with the precision of this.

Definition at line 1628 of file real.hpp.

## ◆ swap()

 void piranha::real::swap ( real & other )
inline

Swap.

Swap this with other.

Parameters
 other swap argument.

Definition at line 976 of file real.hpp.

## ◆ truncate()

 void piranha::real::truncate ( )
inline

Truncate in-place.

Set this to the next representable integer towards zero. If this is infinity or NaN, there will be no effect.

Definition at line 1055 of file real.hpp.

## ◆ truncated()

 real piranha::real::truncated ( ) const
inline

Truncated copy.

Returns
a truncated copy of this.

Definition at line 1066 of file real.hpp.

## ◆ operator!=

template<typename T , typename U >
 auto operator!= ( const T & x, const U & y ) -> decltype(!real::binary_equality(x, y))
friend

Generic inequality operator involving piranha::real.

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

Note that in all comparison operators, apart from piranha::real::operator!=(), if any operand is NaN false will be returned.

Parameters
 x first argument y second argument.
Returns
true if x != y, false otherwise.

Definition at line 1464 of file real.hpp.

## ◆ operator*

template<typename T , typename U >
 auto operator* ( const T & x, const U & y ) -> decltype(real::binary_mul(x, y))
friend

Generic binary multiplication involving piranha::real.

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

The return type is always piranha::real.

Parameters
 x first argument y second argument.
Returns
x * y.
Exceptions
 unspecified any exception thrown by the corresponding in-place operator.

Definition at line 1323 of file real.hpp.

## ◆ operator*=

template<typename T , generic_in_place_enabler< T > = 0>
 T& operator*= ( T & x, const real & r )
friend

Generic in-place multiplication by piranha::real.

Note
This operator is enabled only if T is a non-const interoperable type.

Multiply by a piranha::real in-place. This method will first compute x * r, cast it back to T via static_cast and finally assign the result to x.

Parameters
 x first argument. r second argument.
Returns
reference to x.
Exceptions
 unspecified any exception resulting from the binary operator or by casting piranha::real to T.

Definition at line 1301 of file real.hpp.

## ◆ operator+

template<typename T , typename U >
 auto operator+ ( const T & x, const U & y ) -> decltype(real::binary_add(x, y))
friend

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

The return type is always piranha::real.

Parameters
 x first argument y second argument.
Returns
x + y.
Exceptions
 unspecified any exception thrown by the corresponding in-place operator.

Definition at line 1133 of file real.hpp.

## ◆ operator+=

template<typename T , generic_in_place_enabler< T > = 0>
 T& operator+= ( T & x, const real & r )
friend

Note
This operator is enabled only if T is a non-const interoperable type.

Add a piranha::real in-place. This method will first compute r + x, cast it back to T via static_cast and finally assign the result to x.

Parameters
 x first argument. r second argument.
Returns
reference to x.
Exceptions
 unspecified any exception resulting from the binary operator or by casting piranha::real to T.

Definition at line 1110 of file real.hpp.

## ◆ operator-

template<typename T , typename U >
 auto operator- ( const T & x, const U & y ) -> decltype(real::binary_sub(x, y))
friend

Generic binary subtraction involving piranha::real.

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

The return type is always piranha::real.

Parameters
 x first argument y second argument.
Returns
x - y.
Exceptions
 unspecified any exception thrown by the corresponding in-place operator.

Definition at line 1227 of file real.hpp.

## ◆ operator-=

template<typename T , generic_in_place_enabler< T > = 0>
 T& operator-= ( T & x, const real & r )
friend

Generic in-place subtraction with piranha::real.

Note
This operator is enabled only if T is a non-const interoperable type.

Subtract a piranha::real in-place. This method will first compute x - r, cast it back to T via static_cast and finally assign the result to x.

Parameters
 x first argument. r second argument.
Returns
reference to x.
Exceptions
 unspecified any exception resulting from the binary operator or by casting piranha::real to T.

Definition at line 1205 of file real.hpp.

## ◆ operator/

template<typename T , typename U >
 auto operator/ ( const T & x, const U & y ) -> decltype(real::binary_div(x, y))
friend

Generic binary division involving piranha::real.

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

The return type is always piranha::real.

Parameters
 x first argument y second argument.
Returns
x / y.
Exceptions
 unspecified any exception thrown by the corresponding in-place operator.

Definition at line 1387 of file real.hpp.

## ◆ operator/=

template<typename T , generic_in_place_enabler< T > = 0>
 T& operator/= ( T & x, const real & r )
friend

Generic in-place division by piranha::real.

Note
This operator is enabled only if T is a non-const interoperable type.

Divide by a piranha::real in-place. This method will first compute x / r, cast it back to T via static_cast and finally assign the result to x.

Parameters
 x first argument. r second argument.
Returns
reference to x.
Exceptions
 unspecified any exception resulting from the binary operator or by casting piranha::real to T.

Definition at line 1365 of file real.hpp.

## ◆ operator<

template<typename T , typename U >
 auto operator< ( const T & x, const U & y ) -> decltype(real::binary_less_than(x, y))
friend

Generic less-than operator involving piranha::real.

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

Note that in all comparison operators, apart from piranha::real::operator!=(), if any operand is NaN false will be returned.

Parameters
 x first argument y second argument.
Returns
true if x < y, false otherwise.

Definition at line 1485 of file real.hpp.

## ◆ operator<<

 std::ostream& operator<< ( std::ostream & os, const real & r )
friend

Overload output stream operator for piranha::real.

The output format for finite numbers is normalised scientific notation, where the exponent is signalled by the letter 'e' and suppressed if null.

For non-finite numbers, the string representation is one of "nan", "inf" or "-inf".

Parameters
 os output stream. r piranha::real to be directed to stream.
Returns
reference to os.
Exceptions
 std::invalid_argument if the conversion to string via the MPFR API fails. std::overflow_error if the exponent is smaller than an implementation-defined minimum. unspecified any exception thrown by memory allocation errors in standard containers.

Definition at line 1671 of file real.hpp.

## ◆ operator<=

template<typename T , typename U >
 auto operator<= ( const T & x, const U & y ) -> decltype(real::binary_leq(x, y))
friend

Generic less-than or equal operator involving piranha::real.

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

Note that in all comparison operators, apart from piranha::real::operator!=(), if any operand is NaN false will be returned.

Parameters
 x first argument y second argument.
Returns
true if x <= y, false otherwise.

Definition at line 1509 of file real.hpp.

## ◆ operator==

template<typename T , typename U >
 auto operator== ( const T & x, const U & y ) -> decltype(real::binary_equality(x, y))
friend

Generic equality operator involving piranha::real.

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

Note that in all comparison operators, apart from piranha::real::operator!=(), if any operand is NaN false will be returned.

Parameters
 x first argument y second argument.
Returns
true if x == y, false otherwise.

Definition at line 1443 of file real.hpp.

## ◆ operator>

template<typename T , typename U >
 auto operator> ( const T & x, const U & y ) -> decltype(real::binary_less_than(y, x))
friend

Generic greater-than operator involving piranha::real.

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

Note that in all comparison operators, apart from piranha::real::operator!=(), if any operand is NaN false will be returned.

Parameters
 x first argument y second argument.
Returns
true if x > y, false otherwise.

Definition at line 1533 of file real.hpp.

## ◆ operator>=

template<typename T , typename U >
 auto operator>= ( const T & x, const U & y ) -> decltype(real::binary_leq(y, x))
friend

Generic greater-than or equal operator involving piranha::real.

Note
This template operator is enabled only if either:
• T is piranha::real and U is an interoperable type,
• U is piranha::real and T is an interoperable type,
• both T and U are piranha::real.

Note that in all comparison operators, apart from piranha::real::operator!=(), if any operand is NaN false will be returned.

Parameters
 x first argument y second argument.
Returns
true if x >= y, false otherwise.

Definition at line 1557 of file real.hpp.

## ◆ operator>>

 std::istream& operator>> ( std::istream & is, real & r )
friend

Overload input stream operator for piranha::real.

Equivalent to extracting a line from the stream and then assigning it to r.

Parameters
 is input stream. r real to which the contents of the stream will be assigned.
Returns
reference to is.
Exceptions
 unspecified any exception thrown by the assignment operator from string of piranha::real.

Definition at line 1721 of file real.hpp.

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