Regina Calculation Engine
|
A wrapper class for a native, fixed-precision integer type of the given size. More...
#include <maths/integer.h>
Public Types | |
typedef IntOfSize< bytes >::type | Native |
The native data type used to store this integer. More... | |
Public Member Functions | |
NativeInteger () | |
Initialises this integer to zero. More... | |
NativeInteger (Native value) | |
Initialises this integer to the given value. More... | |
NativeInteger (const NativeInteger< bytes > &value) | |
Initialises this integer to the given value. More... | |
template<bool supportInfinity> | |
NativeInteger (const IntegerBase< supportInfinity > &value) | |
Initialises this integer to the given value. More... | |
bool | isZero () const |
Returns whether or not this integer is zero. More... | |
int | sign () const |
Returns the sign of this integer. More... | |
Native | nativeValue () const |
Returns the value of this integer in its native type. More... | |
NativeInteger & | operator= (const NativeInteger &value) |
Sets this integer to the given value. More... | |
NativeInteger & | operator= (Native value) |
Sets this integer to the given value. More... | |
void | swap (NativeInteger &other) |
Swaps the values of this and the given integer. More... | |
bool | operator== (const NativeInteger &rhs) const |
Determines if this is equal to the given integer. More... | |
bool | operator== (Native rhs) const |
Determines if this is equal to the given integer. More... | |
bool | operator!= (const NativeInteger &rhs) const |
Determines if this is not equal to the given integer. More... | |
bool | operator!= (Native rhs) const |
Determines if this is not equal to the given integer. More... | |
bool | operator< (const NativeInteger &rhs) const |
Determines if this is less than the given integer. More... | |
bool | operator< (Native rhs) const |
Determines if this is less than the given integer. More... | |
bool | operator> (const NativeInteger &rhs) const |
Determines if this is greater than the given integer. More... | |
bool | operator> (Native rhs) const |
Determines if this is greater than the given integer. More... | |
bool | operator<= (const NativeInteger &rhs) const |
Determines if this is less than or equal to the given integer. More... | |
bool | operator<= (Native rhs) const |
Determines if this is less than or equal to the given integer. More... | |
bool | operator>= (const NativeInteger &rhs) const |
Determines if this is greater than or equal to the given integer. More... | |
bool | operator>= (Native rhs) const |
Determines if this is greater than or equal to the given integer. More... | |
NativeInteger & | operator++ () |
The preincrement operator. More... | |
NativeInteger | operator++ (int) |
The postincrement operator. More... | |
NativeInteger & | operator-- () |
The predecrement operator. More... | |
NativeInteger | operator-- (int) |
The postdecrement operator. More... | |
NativeInteger | operator+ (const NativeInteger &other) const |
Adds this to the given integer and returns the result. More... | |
NativeInteger | operator+ (Native other) const |
Adds this to the given integer and returns the result. More... | |
NativeInteger | operator- (const NativeInteger &other) const |
Subtracts the given integer from this and returns the result. More... | |
NativeInteger | operator- (Native other) const |
Subtracts the given integer from this and returns the result. More... | |
NativeInteger | operator* (const NativeInteger &other) const |
Multiplies this by the given integer and returns the result. More... | |
NativeInteger | operator* (Native other) const |
Multiplies this by the given integer and returns the result. More... | |
NativeInteger | operator/ (const NativeInteger &other) const |
Divides this by the given integer and returns the result. More... | |
NativeInteger | operator/ (Native other) const |
Divides this by the given integer and returns the result. More... | |
NativeInteger | divExact (const NativeInteger &other) const |
Divides this by the given integer and returns the result. More... | |
NativeInteger | divExact (Native other) const |
Divides this by the given integer and returns the result. More... | |
NativeInteger | operator% (const NativeInteger &other) const |
Determines the remainder when this integer is divided by the given integer. More... | |
NativeInteger | operator% (Native other) const |
Determines the remainder when this integer is divided by the given integer. More... | |
NativeInteger< bytes > | divisionAlg (const NativeInteger< bytes > &divisor, NativeInteger< bytes > &remainder) const |
Uses the division algorithm to obtain a quotient and remainder when dividing by the given integer. More... | |
NativeInteger | operator- () const |
Determines the negative of this integer. More... | |
NativeInteger & | operator+= (const NativeInteger &other) |
Adds the given integer to this. More... | |
NativeInteger & | operator+= (Native other) |
Adds the given integer to this. More... | |
NativeInteger & | operator-= (const NativeInteger &other) |
Subtracts the given integer from this. More... | |
NativeInteger & | operator-= (Native other) |
Subtracts the given integer from this. More... | |
NativeInteger & | operator*= (const NativeInteger &other) |
Multiplies the given integer by this. More... | |
NativeInteger & | operator*= (Native other) |
Multiplies the given integer by this. More... | |
NativeInteger & | operator/= (const NativeInteger &other) |
Divides this by the given integer. More... | |
NativeInteger & | operator/= (Native other) |
Divides this by the given integer. More... | |
NativeInteger & | divByExact (const NativeInteger &other) |
Divides this by the given integer. More... | |
NativeInteger & | divByExact (Native other) |
Divides this by the given integer. More... | |
NativeInteger & | operator%= (const NativeInteger &other) |
Reduces this integer modulo the given integer. More... | |
NativeInteger & | operator%= (Native other) |
Reduces this integer modulo the given integer. More... | |
void | negate () |
Negates this integer. More... | |
void | gcdWith (const NativeInteger &other) |
Sets this integer to be the greatest common divisor of this and the given integer. More... | |
NativeInteger | gcd (const NativeInteger &other) const |
Determines the greatest common divisor of this and the given integer. More... | |
Friends | |
template<int bytes_> | |
std::ostream & | operator<< (std::ostream &out, const NativeInteger< bytes_ > &large) |
A wrapper class for a native, fixed-precision integer type of the given size.
This class behaves just like native integer arithmetic, where the underlying integer type is signed and stores the given number of bytes. There is no overflow testing, and it is up to the user to ensure that overflows do not occur. On the other hand, this class is almost as fast as native integer arithmetic (i.e., there is very little overhead).
The reason for using this class, instead of working directly in a native integer type, is that this class offers an interface that is compatible with Integer. Only some of the Integer member functions are offered here; however, those that are offered behave just like their Integer counterparts (with the single exception that all arithmetic in NativeInteger is subject to overflow). Developers can therefore switch between integer types easily with minimal changes to their code, or support both Integer and NativeInteger types as template arguments.