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

Integral number of unlimited precision. More...

Inherits __mpz_struct.

Public Member Functions

 Integer (const Integer &b)
 Constructors.
 
 Integer (const mpz_t &b)
 Copy the value from a third party.
 
 Integer (mpz_t &&b) noexcept
 
 Integer (double b)
 conversion
 
 Integer (const Rational &b)
 
 Integer (const char *s)
 Recognizes automatically number base 10, 8, or 16, as well as singular values "±inf" and "nan".
 
 Integer (size_t n, Reserve)
 Reserve space for n bits.
 
 Integer (gmp_randstate_t rnd, unsigned long bits)
 Fill with a prescribed number of random bits.
 
 Integer (gmp_randstate_t rnd, const Integer &upper)
 Construct a random number between 0 and upper.
 
Integeroperator= (const Integer &b)
 Assignment.
 
Integeroperator= (long b)
 Assignment with conversion.
 
Integeroperator= (unsigned long b)
 these three are for libnormaliz again
 
Integeroperator= (double b)
 Assignment with conversion.
 
Integeroperator= (const Rational &b)
 Assignment will fail if b is not integral.
 
Integercopy_from (mpz_srcptr src)
 Assign a copy of data obtained from a third party.
 
Integerset (const char *s)
 Recognizes automatically number base 10, 8, or 16, as well as special values "±inf".
 
bool fill_from_file (int fd)
 
void swap (Integer &b) noexcept
 Efficiently swapping two Integer objects.
 
 operator double () const
 Cast to simpler types.
 
Integeroperator++ ()
 Increment.
 
Integeroperator-- ()
 Decrement.
 
Integernegate () noexcept
 In-place negation.
 
Integeroperator+= (const Integer &b)
 Addition.
 
Integeroperator-= (const Integer &b)
 Subtraction.
 
Integeroperator*= (const Integer &b)
 Multiplication.
 
Integeroperator/= (const Integer &b)
 Division with rounding via truncation.
 
Integeroperator%= (const Integer &b)
 Remainder of division.
 
Integerdiv_exact (const Integer &b)
 b != infinity; but 0/0 allowed
 
Integerdiv_exact (long b)
 0/0 allowed
 
Integeroperator<<= (long k)
 Multiply by or divide through 2**k, truncate to zero.
 
Integeroperator>>= (long k)
 Divide through or multiply by 2**k, truncate to zero.
 
bool bit (unsigned long i) const
 Test for bits.
 
bool odd () const
 Parity.
 
bool even () const
 Parity.
 
bool is_zero () const noexcept
 fast comparison with 0
 
Int compare (const Integer &b) const
 Comparison. The magnitude of the return value is arbitrary, only its sign is relevant.
 
void read (std::istream &is, bool allow_sign=true)
 
size_t strsize (std::ios::fmtflags flags) const
 Calculates the size of the buffer needed to store an ASCII representation of an Integer.
 
void putstr (std::ios::fmtflags flags, char *buf) const
 

Static Public Member Functions

static Integer infinity (Int sgn) noexcept
 Construct an infinite value with a given sign.
 
static Integer fac (long k)
 Factorial.
 
static Integer fibonacci (unsigned long k)
 Fibonacci numbers.
 
static pair< Integer, Integerfibonacci2 (unsigned long k)
 k-th and (k-1)-th Fibonacci numbers
 
static Integer pow (const Integer &a, long k)
 Power.
 
static Integer binom (const Integer &n, long k)
 Binomial coefficient.
 
static Integer binom (long n, long k)
 Binomial coefficient.
 

Protected Member Functions

 Integer (std::nullptr_t)
 uninitialized object
 
void parse (const char *s)
 

Detailed Description

Integral number of unlimited precision.

Powered by GMP.

Constructor & Destructor Documentation

◆ Integer() [1/2]

pm::Integer::Integer ( mpz_t &&  b)
inlineexplicitnoexcept

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

◆ Integer() [2/2]

pm::Integer::Integer ( const Rational b)
inlineexplicit

Construct as a copy of the numerator; b must be integral, otherwise GMP::BadCast exception will be raised

Member Function Documentation

◆ fill_from_file()

bool pm::Integer::fill_from_file ( int  fd)

Fill with bits coming from an open file. The current allocated size is preserved (see constructor with Reserve() argument).

Return values
trueif filled successfully, false if eof or read error occured.

◆ parse()

void pm::Integer::parse ( const char *  s)
protected

parse the string and assign the value. throws an exception in case of syntax errors

◆ putstr()

void pm::Integer::putstr ( std::ios::fmtflags  flags,
char *  buf 
) const

Produces a printable representation of an Integer.

Parameters
bufbuffer of size not less than the return value of strsize().

◆ read()

void pm::Integer::read ( std::istream &  is,
bool  allow_sign = true 
)
Parameters
allow_signwhether leading whitespaces and sign are expected

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