plll
1.0
|
Header for native integer arithmetic in the plll
arithmetic context framework.
More...
#include <sstream>
#include <limits>
#include <cmath>
#include <plll/arithmetic.hpp>
#include "arithmetic-nint-conv.hpp"
Go to the source code of this file.
Namespaces | |
plll | |
Contains the plll library. | |
plll::arithmetic | |
Contains the arithmetic backend of plll . | |
Functions | |
Comparisons. | |
template<typename Type > | |
bool | plll::arithmetic::operator== (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Compares the current integer with the given one for equality. More... | |
template<typename Type > | |
bool | plll::arithmetic::operator!= (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Compares the current integer with the given one for inequality. More... | |
template<typename Type > | |
bool | plll::arithmetic::operator<= (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Compares the current integer with the given one. More... | |
template<typename Type > | |
bool | plll::arithmetic::operator>= (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Compares the current integer with the given one. More... | |
template<typename Type > | |
bool | plll::arithmetic::operator< (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Compares the current integer with the given one. More... | |
template<typename Type > | |
bool | plll::arithmetic::operator> (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Compares the current integer with the given one. More... | |
template<typename Type > | |
int | plll::arithmetic::compare (const NInt< Type > &, const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Compares the two integers. More... | |
template<typename Type > | |
int | plll::arithmetic::compareAbsValues (const NInt< Type > &, const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Compares the two integers in absolute value. More... | |
Operators. | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator- (const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Negates the integer. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator+ (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Adds the two integers and returns the result. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator- (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Subtracts the second from the first integer and returns the result. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator* (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Multiplies the two integers and returns the result. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator/ (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Divides the first by the second integer and returns the result. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator% (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Divides the first by the second integer and returns the remainder. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator<< (const NInt< Type > &a, long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the bitwise left shift of the first integer by the number of bits given by the second integer, and returns the result. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator>> (const NInt< Type > &a, long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the bitwise right shift of the first integer by the number of bits given by the second integer, and returns the result. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator<< (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the bitwise left shift of the first integer by the number of bits given by the second integer, and returns the result. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator>> (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the bitwise right shift of the first integer by the number of bits given by the second integer, and returns the result. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator++ (NInt< Type > &cur, int) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Increments the integer by one and returns the previous value. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::operator-- (NInt< Type > &cur, int) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Decrements the integer by one and returns the previous value. More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator++ (NInt< Type > &cur) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Increments the integer by one and returns the new value. More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator-- (NInt< Type > &cur) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Decreases the integer by one and returns the new value. More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::abs (const NInt< Type > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns the absolute value of i . More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::square (const NInt< Type > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns the square of i . More... | |
Assignment-operation operators. | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator-= (NInt< Type > &cur, const NInt< Type > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Subtracts the integer i from cur . More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator+= (NInt< Type > &cur, const NInt< Type > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Adds the integer i to cur . More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator*= (NInt< Type > &cur, const NInt< Type > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Multiplies the given integer i with cur . More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator/= (NInt< Type > &cur, const NInt< Type > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Divides cur by the given integer i . More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator%= (NInt< Type > &cur, const NInt< Type > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Divides cur by the given integer i and stores the remainder in cur . More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator<<= (NInt< Type > &cur, long i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the bitwise left shift of cur by i bits, and stores the result in cur . More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator>>= (NInt< Type > &cur, long i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the bitwise right shift of cur by i bits, and stores the result in cur . More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator<<= (NInt< Type > &cur, const NInt< Type > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the bitwise left shift of cur by i bits, and stores the result in cur . More... | |
template<typename Type > | |
NInt< Type > & | plll::arithmetic::operator>>= (NInt< Type > &cur, const NInt< Type > &i) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the bitwise right shift of cur by i bits, and stores the result in cur . More... | |
Predicates. | |
template<typename Type > | |
bool | plll::arithmetic::isZero (const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given plll::arithmetic::Integer object for being zero. More... | |
template<typename Type > | |
bool | plll::arithmetic::isOne (const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given plll::arithmetic::Integer object for being one. More... | |
template<typename Type > | |
bool | plll::arithmetic::isPMOne (const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given plll::arithmetic::Integer object for being one or minus one. More... | |
template<typename Type > | |
bool | plll::arithmetic::isPMTwo (const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given plll::arithmetic::Integer object for being two or minus two. More... | |
template<typename Type > | |
bool | plll::arithmetic::isPositive (const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given plll::arithmetic::Integer object for being strictly positive. More... | |
template<typename Type > | |
bool | plll::arithmetic::isNonNegative (const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given plll::arithmetic::Integer object for being positive or zero. More... | |
template<typename Type > | |
bool | plll::arithmetic::isNegative (const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given plll::arithmetic::Integer object for being strictly negative. More... | |
template<typename Type > | |
bool | plll::arithmetic::isNonPositive (const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Tests the given plll::arithmetic::Integer object for being negative or zero. More... | |
Functional versions of operators. | |
template<typename Type > | |
void | plll::arithmetic::add (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Adds a and b and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::sub (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Subtracts b from a and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::addmul (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Multiplies a and b and adds the result to r . More... | |
template<typename Type > | |
void | plll::arithmetic::submul (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Multiplies a and b and subtracts the result from r . More... | |
template<typename Type > | |
void | plll::arithmetic::mul (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Multiplies a with b and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::div (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Divides a by b and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::divmod (NInt< Type > &q, NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Stores quotient and remainder of the division of a by b in q respectively r . More... | |
template<typename Type > | |
void | plll::arithmetic::mod (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Takes the remainder of the division of a by b and stores it in r . More... | |
template<typename Type > | |
void | plll::arithmetic::shl (NInt< Type > &r, const NInt< Type > &a, long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Shifts a by b bits to the left and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::shr (NInt< Type > &r, const NInt< Type > &a, long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Shifts a by b bits to the left and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::shl (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Shifts a by b bits to the left and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::shr (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Shifts a by b bits to the left and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::increment (NInt< Type > &r, const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Increments a by one and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::decrement (NInt< Type > &r, const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Decrements a by one and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::neg (NInt< Type > &r, const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Negates a and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::abs (NInt< Type > &r, const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Takes the absolute value of a and stores the result in r . More... | |
template<typename Type > | |
void | plll::arithmetic::square (NInt< Type > &r, const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the square of a and stores the result in r . More... | |
Stream input/output. | |
template<typename Type > | |
std::ostream & | plll::arithmetic::operator<< (std::ostream &, const NInt< Type > &) |
Outputs the integer on the given output stream. | |
template<typename Type > | |
std::istream & | plll::arithmetic::operator>> (std::istream &, NInt< Type > &) |
Reads the integer from the given input stream. | |
Setting to specific constants. | |
template<typename Type > | |
void | plll::arithmetic::setZero (NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Sets the given integer to zero. | |
template<typename Type > | |
void | plll::arithmetic::setOne (NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Sets the given integer to one. | |
Sign querying/modification. | |
template<typename Type > | |
int | plll::arithmetic::sign (const NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Returns the sign of the given integer. More... | |
template<typename Type > | |
void | plll::arithmetic::makeAbs (NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Makes the operand non-negative. More... | |
Bit manipulation. | |
template<typename Type > | |
int | plll::arithmetic::bit (const NInt< Type > &x, long n) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Returns the n bit of in the usual binary representation. More... | |
template<typename Type > | |
void | plll::arithmetic::setbit (NInt< Type > &x, long n, bool value=true) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Sets the n -th bit of to value . More... | |
Exponentiation. | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::power (const NInt< Type > &a, long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns a raised to the power of b . More... | |
template<typename Type > | |
void | plll::arithmetic::power (NInt< Type > &r, const NInt< Type > &a, long b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Raises a to the power b and stores the result in r . More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::power (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns a raised to the power of b . More... | |
template<typename Type > | |
void | plll::arithmetic::power (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Raises a to the power b and stores the result in r . More... | |
Integer approximation. | |
template<typename Type > | |
void | plll::arithmetic::sqrtCeil (NInt< Type > &r, const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and stores the result in r . More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::sqrtCeil (const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns . More... | |
template<typename Type > | |
void | plll::arithmetic::sqrtFloor (NInt< Type > &r, const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and stores the result in r . More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::sqrtFloor (const NInt< Type > &a) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns . More... | |
template<typename Type > | |
long | plll::arithmetic::ceilOfLog2 (const NInt< Type > &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns . More... | |
template<typename Type > | |
long | plll::arithmetic::floorOfLog2 (const NInt< Type > &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns . More... | |
template<typename Type > | |
long | plll::arithmetic::approxLog2 (const NInt< Type > &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Quickly approximates and returns the approximation. More... | |
template<typename Type > | |
long | plll::arithmetic::bitLength (const NInt< Type > &x) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns n such that . More... | |
template<typename Type > | |
void | plll::arithmetic::floorDiv (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and stores the result in r . More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::floorDiv (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns . More... | |
template<typename Type > | |
void | plll::arithmetic::ceilDiv (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and stores the result in r . More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::ceilDiv (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns . More... | |
template<typename Type > | |
void | plll::arithmetic::roundDiv (NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes (rounding to the next integer) and stores the result in r . More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::roundDiv (const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns (rounding to the next integer). More... | |
Euclidean ring functions. | |
template<typename Type > | |
void | plll::arithmetic::euclideanDivision (NInt< Type > &q, NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes an Euclidean Division of a by b . More... | |
template<typename Type > | |
void | plll::arithmetic::euclideanDivisionPos (NInt< Type > &q, NInt< Type > &r, const NInt< Type > &a, const NInt< Type > &b) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes an Euclidean Division of a by b . More... | |
template<typename Type > | |
void | plll::arithmetic::GCD (NInt< Type > &r, const NInt< Type > &x, const NInt< Type > &y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the non-negative Greatest Common Divisior r of x and y . More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::GCD (const NInt< Type > &x, const NInt< Type > &y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns the non-negative Greatest Common Divisior of x and y . More... | |
template<typename Type > | |
void | plll::arithmetic::XGCD (NInt< Type > &r, NInt< Type > &a, NInt< Type > &b, const NInt< Type > &x, const NInt< Type > &y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the non-negative extended Greatest Common Divisior r of x and y . More... | |
template<typename Type > | |
void | plll::arithmetic::LCM (NInt< Type > &r, const NInt< Type > &x, const NInt< Type > &y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes the non-negative Least Common Multiple r of x and y . More... | |
template<typename Type > | |
NInt< Type > | plll::arithmetic::LCM (const NInt< Type > &x, const NInt< Type > &y) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Computes and returns the non-negative Least Common Multiple of x and y . More... | |
Swap functions. | |
template<typename Type > | |
void | plll::arithmetic::swap (NInt< Type > &, NInt< Type > &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE |
Swaps two plll::arithmetic::NInt<> objects. | |
Header for native integer arithmetic in the plll
arithmetic context framework.
This header provides a wrapper for native integer types such as int
, long int
and long long
. It provides the arithmetic context template plll::arithmetic::NIntContext<>
as described in Arithmetic Contexts.
Concrete integers are represented by the plll::arithmetic::NInt<>
template.
Definition in file arithmetic-nint.hpp.