Polymake Template Library (PTL): pm::Rational Class Reference
Polymake Template Library (PTL)  4.2

Rational number with unlimited precision. More...

Inherits __mpq_struct.

Public Types

typedef RationalParticle< true > num_proxy
 Separate access to numerator and denominator.
 

Public Member Functions

 Rational (const Rational &b)
 Constructors.
 
 Rational (const mpq_t &b)
 Copy the value from a third party.
 
 Rational (mpq_t &&b) noexcept
 
 Rational (const Integer &b)
 Create a Rational from an integral number.
 
 Rational (const mpz_t &b)
 Copy the numerator value from a third party.
 
 Rational (mpz_t &&b)
 
 Rational (const Integer &num, const Integer &den)
 Create a Rational as the quotient of two integrals, represented as Integer, long, or int.
 
 Rational (const mpz_t &num, const mpz_t &den)
 Copy or steal numerator and denominator values from a third party.
 
 Rational (const char *s)
 Parse a string "num/den", "num", or "±inf".
 
Rationaloperator= (const Rational &b)
 Assignment.
 
Rationalcopy_from (mpq_srcptr src)
 Assign a copy of data obtained from a third party.
 
Rationalset (const Integer &num, const Integer &den)
 Assign numerator and denominator from separate sources.
 
void swap (Rational &b)
 Exchange the values.
 
 operator double () const
 Cast to simpler types.
 
Rationaloperator++ ()
 Increment.
 
Rationalnegate ()
 In-place negation.
 
Rationaloperator+= (const Rational &b)
 Addition.
 
Rationaloperator-= (const Rational &b)
 Subtraction.
 
Rationaloperator*= (const Rational &b)
 Multiplication.
 
Rationaloperator/= (const Rational &b)
 Division.
 
Rationaloperator<<= (long k)
 Multiply with or divide through 2**k.
 
Rationaloperator>>= (long k)
 Divide through or multiply with 2**k.
 
Integer floor () const
 The closest integral not greater than this.
 
Integer ceil () const
 The closest integral not smaller than the given value.
 
Integer trunc () const
 Truncation toward zero.
 
bool is_zero () const noexcept
 fast comparison with 0
 
bool is_integral () const noexcept
 
Int compare (const Rational &b) const
 
Int compare (double b) const
 Comparison.
 

Static Public Member Functions

static Rational infinity (Int sgn)
 Construct an infinite value.
 
static Rational pow (const Rational &a, long k)
 Power.
 
static Rational pow (const Integer &a, long k)
 Power.
 

Protected Member Functions

 Rational (std::nullptr_t)
 uninitialized object
 

Detailed Description

Rational number with unlimited precision.

Powered by GMP

Constructor & Destructor Documentation

◆ Rational() [1/2]

pm::Rational::Rational ( mpq_t &&  b)
inlineexplicitnoexcept

Steal the value from a third party The source must be re-initialized if it's going to be used afterwards

◆ Rational() [2/2]

pm::Rational::Rational ( mpz_t &&  b)
inlineexplicit

Steal the numerator value from a third party The source must be re-initialized if it's going to be used afterwards

Member Function Documentation

◆ compare()

Int pm::Rational::compare ( const Rational b) const
inline

Comparison. The magnitude of the return value is arbitrary, only its sign is relevant.

◆ is_integral()

bool pm::Rational::is_integral ( ) const
inlinenoexcept

check whether the denominator equals 1 for infinite values, returns true as well


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