plll  1.0
arithmetic-gmp.hpp File Reference

Header for arbitrary precision integer and floating point arithmetic, provided by GMP and MPFR. More...

#include <plll/config.hpp>
#include <stdint.h>
#include <gmp.h>
#include <mpfr.h>
#include <cmath>
#include <math.h>
#include <limits>
#include <iosfwd>
#include <cassert>
#include <utility>
#include <algorithm>
#include <plll/helper.hpp>
#include "arithmetic-gmp-iops.hpp"
#include "arithmetic-gmp-rops.hpp"
#include "arithmetic-gmp-conv.hpp"

Go to the source code of this file.

Classes

class  plll::arithmetic::Integer
 Represents an arbitrary precision integer. More...
 
class  plll::arithmetic::IntegerContext
 Represents an arithmetic context for arbitrary precision integer. More...
 
struct  plll::arithmetic::Real::PrecisionInit
 
class  plll::arithmetic::RandomNumberGenerator
 Represents a random number generator. More...
 
class  plll::arithmetic::Real
 Represents an arbitrary precision floating point value. More...
 
class  plll::arithmetic::RealContext
 Represents an arithmetic context for arbitrary precision floating point values. More...
 
class  plll::arithmetic::IntegerContext::UniformRNG
 
class  plll::arithmetic::RealContext::UniformRNG
 

Namespaces

 plll
 Contains the plll library.
 
 plll::arithmetic
 Contains the arithmetic backend of plll.
 

Functions

RealContext & plll::arithmetic::getThreadRealContext ()
 Retrieves a context for the current thread. The context is thread local and cannot be accessed by this method from other threads.
 
void plll::arithmetic::initArithmeticThreadAllocators ()
 Initializes the local thread allocator for the current thread, and sets the GMP and MPFR allocators to the local thread allocator. More...
 
Swap functions.
void plll::arithmetic::swap (plll::arithmetic::Integer &, plll::arithmetic::Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Swaps two plll::arithmetic::Integer objects.
 
void plll::arithmetic::swap (plll::arithmetic::Real &, plll::arithmetic::Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Swaps two plll::arithmetic::Real objects.
 
Predicates.
bool plll::arithmetic::isZero (const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Integer object for being zero. More...
 
bool plll::arithmetic::isZero (const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Real object for being zero. More...
 
bool plll::arithmetic::isOne (const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Integer object for being one. More...
 
bool plll::arithmetic::isPMOne (const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Integer object for being one or minus one. More...
 
bool plll::arithmetic::isPMTwo (const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Integer object for being two or minus two. More...
 
bool plll::arithmetic::isOne (const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Real object for being one. More...
 
bool plll::arithmetic::isPositive (const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Integer object for being strictly positive. More...
 
bool plll::arithmetic::isPositive (const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Real object for being strictly positive. More...
 
bool plll::arithmetic::isNonNegative (const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Integer object for being positive or zero. More...
 
bool plll::arithmetic::isNonNegative (const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Real object for being positive or zero. More...
 
bool plll::arithmetic::isNegative (const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Integer object for being strictly negative. More...
 
bool plll::arithmetic::isNegative (const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Real object for being strictly negative. More...
 
bool plll::arithmetic::isNonPositive (const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Integer object for being negative or zero. More...
 
bool plll::arithmetic::isNonPositive (const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Tests the given plll::arithmetic::Real object for being negative or zero. More...
 
Euclidean ring functions.
void plll::arithmetic::euclideanDivision (Integer &q, Integer &r, const Integer &a, const Integer &b)
 Computes an Euclidean Division of a by b. More...
 
void plll::arithmetic::euclideanDivisionPos (Integer &q, Integer &r, const Integer &a, const Integer &b)
 Computes an Euclidean Division of a by b. More...
 
void plll::arithmetic::GCD (Integer &r, const Integer &x, const Integer &y)
 Computes the non-negative Greatest Common Divisior r of x and y. More...
 
void plll::arithmetic::XGCD (Integer &r, Integer &a, Integer &b, const Integer &x, const Integer &y)
 Computes the non-negative extended Greatest Common Divisior r of x and y. More...
 
void plll::arithmetic::LCM (Integer &r, const Integer &x, const Integer &y)
 Computes the non-negative Least Common Multiple r of x and y. More...
 
Stream input/output.
std::ostream & plll::arithmetic::operator<< (std::ostream &, const Integer &)
 Outputs the integer on the given output stream.
 
std::istream & plll::arithmetic::operator>> (std::istream &, Integer &)
 Reads the integer from the given input stream.
 
std::ostream & plll::arithmetic::operator<< (std::ostream &, const Real &)
 Outputs the floating point number on the given output stream.
 
std::istream & plll::arithmetic::operator>> (std::istream &, Real &)
 Reads the floating point number from the given input stream.
 
Setting to specific constants.
void plll::arithmetic::setNaN (Real &)
 Sets the given floating point number to Not a Number.
 
void plll::arithmetic::setInfinity (Real &r, bool sign=true)
 Sets the given floating point number to $\pm \infty$. More...
 
void plll::arithmetic::setZero (Integer &)
 Sets the given integer to zero.
 
void plll::arithmetic::setZero (Real &r, bool sign=true)
 Sets the given floating point number to $\pm 0$. More...
 
void plll::arithmetic::setOne (Integer &)
 Sets the given integer to one.
 
void plll::arithmetic::setOne (Real &)
 Sets the given floating point number to one.
 
Comparisons.
int plll::arithmetic::compare (const Integer &a, const Integer &b)
 Compares the two integers. More...
 
int plll::arithmetic::compare (const Real &a, const Real &b)
 Compares the two floating point numbers. More...
 
int plll::arithmetic::compareAbsValues (const Integer &a, const Integer &b)
 Compares the two integers in absolute value. More...
 
int plll::arithmetic::compareAbsValues (const Real &a, const Real &b)
 Compares the two floating point numbers in absolute value. More...
 
Sign querying/modification.
int plll::arithmetic::sign (const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Returns the sign of the given integer. More...
 
int plll::arithmetic::sign (const Real &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Returns the sign of the given floating point number. More...
 
void plll::arithmetic::makeAbs (Integer &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Makes the operand non-negative. More...
 
void plll::arithmetic::makeAbs (Real &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Makes the operand non-negative. More...
 
Bit manipulation.
int plll::arithmetic::bit (const Integer &x, long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Returns the n bit of $|x|$ in the usual binary representation. More...
 
void plll::arithmetic::setbit (Integer &x, long n, bool value=true)
 Sets the n-th bit of $|x|$ to value. More...
 
Functional versions of operators.
void plll::arithmetic::increment (Integer &r, const Integer &a)
 Increments a by one and stores the result in r. More...
 
void plll::arithmetic::decrement (Integer &r, const Integer &a)
 Decrements a by one and stores the result in r. More...
 
void plll::arithmetic::add (Integer &r, const Integer &a, const Integer &b)
 Adds a and b and stores the result in r. More...
 
void plll::arithmetic::sub (Integer &r, const Integer &a, const Integer &b)
 Subtracts b from a and stores the result in r. More...
 
void plll::arithmetic::mul (Integer &r, const Integer &a, const Integer &b)
 Multiplies a with b and stores the result in r. More...
 
void plll::arithmetic::neg (Integer &r, const Integer &a)
 Negates a and stores the result in r. More...
 
void plll::arithmetic::div (Integer &r, const Integer &a, const Integer &b)
 Divides a by b and stores the result in r. More...
 
void plll::arithmetic::mod (Integer &r, const Integer &a, const Integer &b)
 Takes the remainder of the division of a by b and stores it in r. More...
 
void plll::arithmetic::divmod (Integer &q, Integer &r, const Integer &a, const Integer &b)
 Stores quotient and remainder of the division of a by b in q respectively r. More...
 
void plll::arithmetic::abs (Integer &r, const Integer &a)
 Takes the absolute value of a and stores the result in r. More...
 
void plll::arithmetic::addmul (Integer &r, const Integer &a, const Integer &b)
 Multiplies a and b and adds the result to r. More...
 
void plll::arithmetic::submul (Integer &r, const Integer &a, const Integer &b)
 Multiplies a and b and subtracts the result from r. More...
 
void plll::arithmetic::band (Integer &r, const Integer &a, const Integer &b)
 Computes the bitwise and of a and b and stores the result in r. More...
 
void plll::arithmetic::bor (Integer &r, const Integer &a, const Integer &b)
 Computes the bitwise or of a and b and stores the result in r. More...
 
void plll::arithmetic::bxor (Integer &r, const Integer &a, const Integer &b)
 Computes the bitwise exclusive or of a and b and stores the result in r. More...
 
void plll::arithmetic::bneg (Integer &r, const Integer &a)
 Takes the bitwise complement of a and stores the result in r. More...
 
void plll::arithmetic::shl (Integer &r, const Integer &a, long b)
 Shifts a by b bits to the left and stores the result in r. More...
 
void plll::arithmetic::shl (Integer &r, const Integer &a, const Integer &b)
 Shifts a by b bits to the right and stores the result in r. More...
 
void plll::arithmetic::shr (Integer &r, const Integer &a, long b)
 Shifts a by b bits to the left and stores the result in r. More...
 
void plll::arithmetic::shr (Integer &r, const Integer &a, const Integer &b)
 Shifts a by b bits to the right and stores the result in r. More...
 
void plll::arithmetic::square (Integer &r, const Integer &a)
 Computes the square of a and stores the result in r. More...
 
void plll::arithmetic::add (Real &r, const Real &a, const Real &b)
 Adds a and b and stores the result in r. More...
 
void plll::arithmetic::sub (Real &r, const Real &a, const Real &b)
 Subtracts b from a and stores the result in r. More...
 
void plll::arithmetic::mul (Real &r, const Real &a, const Real &b)
 Multiplies a with b and stores the result in r. More...
 
void plll::arithmetic::div (Real &r, const Real &a, const Real &b)
 Divides a by b and stores the result in r. More...
 
void plll::arithmetic::mod (Real &r, const Real &a, const Real &b)
 Takes the remainder of the division of a by b and stores it in r. More...
 
void plll::arithmetic::divmod (Real &q, Real &r, const Real &a, const Real &b)
 Stores quotient and remainder of the division of a by b in q respectively r. More...
 
void plll::arithmetic::shl (Real &r, const Real &a, const Real &b)
 Multiplies a by $2^b$ and stores the result in r. More...
 
void plll::arithmetic::shr (Real &r, const Real &a, const Real &b)
 Multiplies a by $2^{-b}$ and stores the result in r. More...
 
void plll::arithmetic::shl (Real &r, const Real &a, long b)
 Multiplies a by $2^b$ and stores the result in r. More...
 
void plll::arithmetic::shr (Real &r, const Real &a, long b)
 Multiplies a by $2^{-b}$ and stores the result in r. More...
 
void plll::arithmetic::increment (Real &r, const Real &a)
 Increments a by one and stores the result in r. More...
 
void plll::arithmetic::decrement (Real &r, const Real &a)
 Decrements a by one and stores the result in r. More...
 
void plll::arithmetic::neg (Real &r, const Real &a)
 Negates a and stores the result in r. More...
 
void plll::arithmetic::abs (Real &r, const Real &a)
 Takes the absolute value of a and stores the result in r. More...
 
void plll::arithmetic::addmul (Real &r, const Real &a, const Real &b)
 Multiplies a and b and adds the result to r. More...
 
void plll::arithmetic::submul (Real &r, const Real &a, const Real &b)
 Multiplies a and b and subtracts the result from r. More...
 
void plll::arithmetic::square (Real &r, const Real &a)
 Computes the square of a and stores the result in r. More...
 
Exponentiation.
void plll::arithmetic::power (Integer &r, const Integer &a, long b)
 Raises a to the power b and stores the result in r. More...
 
void plll::arithmetic::power (Integer &r, const Integer &a, const Integer &b)
 Raises a to the power b and stores the result in r. More...
 
void plll::arithmetic::power (Real &res, const Real &a, long b)
 
void plll::arithmetic::power (Real &res, const Real &a, const Integer &b)
 Raises a to the power b and stores the result in res. More...
 
void plll::arithmetic::power (Real &res, const Real &a, const Real &b)
 Raises a to the power b and stores the result in res. More...
 
Integer approximation.
void plll::arithmetic::sqrtCeil (Integer &r, const Integer &a)
 Computes $\lceil\sqrt{a}\rceil$ and stores the result in r. More...
 
void plll::arithmetic::sqrtFloor (Integer &r, const Integer &a)
 Computes $\lfloor\sqrt{a}\rfloor$ and stores the result in r. More...
 
long plll::arithmetic::approxLog2 (const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Quickly approximates $\log_2 |x|$ and returns the approximation. More...
 
long plll::arithmetic::ceilOfLog2 (const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Computes and returns $\lceil \log_2 |x| \rceil$. More...
 
long plll::arithmetic::floorOfLog2 (const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Computes and returns $\lfloor \log_2 |x| \rfloor$. More...
 
long plll::arithmetic::bitLength (const Integer &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
 Computes and returns n such that $2^{n-1} \le |x| < 2^n$. More...
 
void plll::arithmetic::floorDiv (Integer &r, const Integer &a, const Integer &b)
 Computes $\lfloor \tfrac{a}{b} \rfloor$ and stores the result in r. More...
 
void plll::arithmetic::ceilDiv (Integer &r, const Integer &a, const Integer &b)
 Computes $\lceil \tfrac{a}{b} \rceil$ and stores the result in r. More...
 
void plll::arithmetic::roundDiv (Integer &r, const Integer &a, const Integer &b)
 Computes $\lfloor \tfrac{a}{b} \rceil$ (rounding to the next integer) and stores the result in r. More...
 
Trigonometric functions.
void plll::arithmetic::sin (Real &res, const Real &a)
 Computes the sine of a and stores the result in res. More...
 
void plll::arithmetic::cos (Real &res, const Real &a)
 Computes the cosine of a and stores the result in res. More...
 
void plll::arithmetic::tan (Real &res, const Real &a)
 Computes the tangent of a and stores the result in res. More...
 
void plll::arithmetic::asin (Real &res, const Real &a)
 Computes the arcsine of a and stores the result in res. More...
 
void plll::arithmetic::acos (Real &res, const Real &a)
 Computes the arccosine of a and stores the result in res. More...
 
void plll::arithmetic::atan (Real &res, const Real &a)
 Computes the arctangent of a and stores the result in res. More...
 
void plll::arithmetic::atan2 (Real &res, const Real &y, const Real &x)
 Computes the arctangent of $\tfrac{y}{x}$and stores the result inres. The signs ofxandy` are used to determine the quadrant and yield a result in $[-\pi, \pi]$. More...
 
Exponential and logarithmic functions.
void plll::arithmetic::exp (Real &res, const Real &a)
 Computes the exponential function at a and stores the result in res. More...
 
void plll::arithmetic::log (Real &res, const Real &a)
 Computes the natural logarithm of a and stores the result in res. More...
 
void plll::arithmetic::log2 (Real &res, const Real &a)
 Computes the logarithm of a to base 2 and stores the result in res. More...
 
void plll::arithmetic::log10 (Real &res, const Real &a)
 Computes the logarithm of a to base 10 and stores the result in res. More...
 
void plll::arithmetic::sqrt (Real &res, const Real &a)
 Computes the square root of a and stores the result in res. More...
 
Special functions.
void plll::arithmetic::gamma (Real &res, const Real &a)
 Computes the Gamma function at a and stores the result in res. More...
 
void plll::arithmetic::lgamma (Real &res, const Real &a)
 Computes the logarithm of the absolute value of the Gamma function at a and stores the result in res. More...
 
void plll::arithmetic::lgamma (Real &res, int &sign, const Real &a)
 Computes the logarithm of the absolute value of the Gamma function at a and stores the result in res. The sign of the Gamma function at a is stored in sign. More...
 

Detailed Description

Header for arbitrary precision integer and floating point arithmetic, provided by GMP and MPFR.

This header provides arbitrary precision integer and floating point arithmetic for plll. It provides plll::arithmetic::IntegerContext and plll::arithmetic::RealContext, two arithmetic contexts as described in Arithmetic Contexts.

Concrete integers are represented by plll::arithmetic::Integer objects and concrete floating point numbers are represented by plll::arithmetic::Real objects. All expressions are represented by plll::arithmetic::expressions::Expression<> templates.

Definition in file arithmetic-gmp.hpp.