Regina 7.3 Calculation Engine
|
A wrapper class for a native, fixed-precision integer type of the given size. More...
#include <maths/integer.h>
Public Types | |
using | Native = typename IntOfSize< bytes >::type |
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) noexcept |
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... | |
std::pair< NativeInteger, NativeInteger > | divisionAlg (const NativeInteger &divisor) 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... | |
bool | isInfinite () const |
Returns whether this integer is infinity. More... | |
void | tryReduce () |
A do-nothing routine that ensures that this integer is using a native C/C++ integer representation. More... | |
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.
This class supports copying but does not implement separate move operations, since its internal data is so small that copying is just as efficient. It implements the C++ Swappable requirement via its own member and global swap() functions, for consistency with the Integer and LargeInteger classes.
using regina::NativeInteger< bytes >::Native = typename IntOfSize<bytes>::type |
The native data type used to store this integer.
|
inline |
Initialises this integer to zero.
|
inline |
Initialises this integer to the given value.
value | the new value of this integer. |
|
inline |
Initialises this integer to the given value.
value | the new value of this integer. |
|
inlineexplicit |
Initialises this integer to the given value.
This constructor is marked as explicit in the hope of avoiding accidental (and unintentional) mixing of integer classes.
It is the programmer's reponsibility to ensure that the given value fits within the required range. If the given value is too large or small to fit into this native type, then this new NativeInteger will have an undefined initial value.
value | the new value of this integer. |
|
inline |
Divides this by the given integer.
For native integers, this routine is identical to operator /=.
other | the integer to divide this by. |
|
inline |
Divides this by the given integer.
For native integers, this routine is identical to operator /=.
other | the integer to divide this by. |
|
inline |
Divides this by the given integer and returns the result.
For native integers, this is identical to operator /.
other | the integer to divide this by. |
|
inline |
Divides this by the given integer and returns the result.
For native integers, this is identical to operator /.
other | the integer to divide this by. |
|
inline |
Uses the division algorithm to obtain a quotient and remainder when dividing by the given integer.
Suppose this integer is n and we pass the divisor d. The division algorithm describes the result of dividing n by d; in particular, it expresses n = qd + r
, where q is the quotient and r is the remainder.
The division algorithm is precise about which values of q and r are chosen; in particular it chooses the unique r in the range 0 ≤ r < |d|
.
Note that this differs from other division routines in this class, in that it always rounds to give a non-negative remainder. Thus (-7).divisionAlg(3) gives quotient -3 and remainder 2, whereas (-7)/3 gives quotient -2 and (-7)%3 gives remainder -1.
In the special case where the given divisor is 0 (not allowed by the usual division algorithm), this routine selects quotient 0 and remainder n.
divisor | the divisor d. |
|
inline |
Determines the greatest common divisor of this and the given integer.
This integer is not changed.
The result is guaranteed to be non-negative. As a special case, gcd(0,0) is considered to be zero.
other | the integer whose greatest common divisor with this will be found. |
void regina::NativeInteger< bytes >::gcdWith | ( | const NativeInteger< bytes > & | other | ) |
Sets this integer to be the greatest common divisor of this and the given integer.
The result is guaranteed to be non-negative. As a special case, gcd(0,0) is considered to be zero.
other | the integer whose greatest common divisor with this will be found. |
Now everything is non-negative. The following code is based on Stein's binary GCD algorithm.
|
inline |
Returns whether this integer is infinity.
Since NativeInteger cannot represent infinity, this routine will always return false
. This routine is simply provided for compatibility with LargeInteger (where infinity is allowed).
false
, since a NativeInteger can never be infinity.
|
inline |
Returns whether or not this integer is zero.
true
if and only if this integer is zero.
|
inline |
Returns the value of this integer in its native type.
|
inline |
Negates this integer.
This integer is changed to reflect the result.
|
inline |
Determines if this is not equal to the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this and the given integer are not equal.
|
inline |
Determines if this is not equal to the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this and the given integer are not equal.
|
inline |
Determines the remainder when this integer is divided by the given integer.
If non-zero, the result will have the same sign as this integer. This integer is not changed.
For a division routine that always returns a non-negative remainder, see divisionAlg().
other | the integer to divide this by. |
|
inline |
Determines the remainder when this integer is divided by the given integer.
If non-zero, the result will have the same sign as this integer. This integer is not changed.
For a division routine that always returns a non-negative remainder, see divisionAlg().
other | the integer to divide this by. |
|
inline |
Reduces this integer modulo the given integer.
If non-zero, the result will have the same sign as the original value of this integer. This integer is changed to reflect the result.
For a mod routine that always returns a non-negative remainder, see divisionAlg().
other | the integer modulo which this integer will be reduced. |
|
inline |
Reduces this integer modulo the given integer.
If non-zero, the result will have the same sign as the original value of this integer. This integer is changed to reflect the result.
For a mod routine that always returns a non-negative remainder, see divisionAlg().
other | the integer modulo which this integer will be reduced. |
|
inline |
Multiplies this by the given integer and returns the result.
This integer is not changed.
other | the integer to multiply by this integer. |
|
inline |
Multiplies this by the given integer and returns the result.
This integer is not changed.
other | the integer to multiply by this integer. |
|
inline |
Multiplies the given integer by this.
This integer is changed to reflect the result.
other | the integer to multiply with this integer. |
|
inline |
Multiplies the given integer by this.
This integer is changed to reflect the result.
other | the integer to multiply with this integer. |
|
inline |
Adds this to the given integer and returns the result.
This integer is not changed.
other | the integer to add to this integer. |
|
inline |
Adds this to the given integer and returns the result.
This integer is not changed.
other | the integer to add to this integer. |
|
inline |
The preincrement operator.
This operator increments this integer by one, and returns a reference to the integer after the increment.
|
inline |
The postincrement operator.
This operator increments this integer by one, and returns a copy of the integer before the increment.
|
inline |
Adds the given integer to this.
This integer is changed to reflect the result.
other | the integer to add to this integer. |
|
inline |
Adds the given integer to this.
This integer is changed to reflect the result.
other | the integer to add to this integer. |
|
inline |
Determines the negative of this integer.
This integer is not changed.
|
inline |
Subtracts the given integer from this and returns the result.
This integer is not changed.
other | the integer to subtract from this integer. |
|
inline |
Subtracts the given integer from this and returns the result.
This integer is not changed.
other | the integer to subtract from this integer. |
|
inline |
The predecrement operator.
This operator decrements this integer by one, and returns a reference to the integer after the decrement.
|
inline |
The postdecrement operator.
This operator decrements this integer by one, and returns a copy of the integer before the decrement.
|
inline |
Subtracts the given integer from this.
This integer is changed to reflect the result.
other | the integer to subtract from this integer. |
|
inline |
Subtracts the given integer from this.
This integer is changed to reflect the result.
other | the integer to subtract from this integer. |
|
inline |
Divides this by the given integer and returns the result.
The result will be truncated to an integer, i.e. rounded towards zero. This integer is not changed.
For a division routine that always rounds down, see divisionAlg().
other | the integer to divide this by. |
|
inline |
Divides this by the given integer and returns the result.
The result will be truncated to an integer, i.e. rounded towards zero. This integer is not changed.
For a division routine that always rounds down, see divisionAlg().
other | the integer to divide this by. |
|
inline |
Divides this by the given integer.
The result will be truncated to an integer, i.e. rounded towards zero. This integer is changed to reflect the result.
For a division routine that always rounds down, see divisionAlg().
other | the integer to divide this by. |
|
inline |
Divides this by the given integer.
The result will be truncated to an integer, i.e. rounded towards zero. This integer is changed to reflect the result.
For a division routine that always rounds down, see divisionAlg().
other | the integer to divide this by. |
|
inline |
Determines if this is less than the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this is less than the given integer.
|
inline |
Determines if this is less than the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this is less than the given integer.
|
inline |
Determines if this is less than or equal to the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this is less than or equal to the given integer.
|
inline |
Determines if this is less than or equal to the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this is less than or equal to the given integer.
|
inline |
Sets this integer to the given value.
value | the new value of this integer. |
|
inline |
Sets this integer to the given value.
value | the new value of this integer. |
|
inline |
Determines if this is equal to the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this and the given integer are equal.
|
inline |
Determines if this is equal to the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this and the given integer are equal.
|
inline |
Determines if this is greater than the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this is greater than the given integer.
|
inline |
Determines if this is greater than the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this is greater than the given integer.
|
inline |
Determines if this is greater than or equal to the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this is greater than or equal to the given integer.
|
inline |
Determines if this is greater than or equal to the given integer.
rhs | the integer with which this will be compared. |
true
if and only if this is greater than or equal to the given integer.
|
inline |
Returns the sign of this integer.
|
inlinenoexcept |
Swaps the values of this and the given integer.
other | the integer whose value will be swapped with this. |
|
inline |
A do-nothing routine that ensures that this integer is using a native C/C++ integer representation.
Since the NativeInteger class always uses a native representation, this routine does nothing at all. This routine is simply provided for compatibility with Regina's arbitrary-precision Integer and LargeInteger classes.