Regina Calculation Engine
Public Types | Public Member Functions | Friends | List of all members
regina::NativeInteger< bytes > Class Template Reference

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...
 
NativeIntegeroperator= (const NativeInteger &value)
 Sets this integer to the given value. More...
 
NativeIntegeroperator= (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...
 
NativeIntegeroperator++ ()
 The preincrement operator. More...
 
NativeInteger operator++ (int)
 The postincrement operator. More...
 
NativeIntegeroperator-- ()
 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...
 
NativeIntegeroperator+= (const NativeInteger &other)
 Adds the given integer to this. More...
 
NativeIntegeroperator+= (Native other)
 Adds the given integer to this. More...
 
NativeIntegeroperator-= (const NativeInteger &other)
 Subtracts the given integer from this. More...
 
NativeIntegeroperator-= (Native other)
 Subtracts the given integer from this. More...
 
NativeIntegeroperator*= (const NativeInteger &other)
 Multiplies the given integer by this. More...
 
NativeIntegeroperator*= (Native other)
 Multiplies the given integer by this. More...
 
NativeIntegeroperator/= (const NativeInteger &other)
 Divides this by the given integer. More...
 
NativeIntegeroperator/= (Native other)
 Divides this by the given integer. More...
 
NativeIntegerdivByExact (const NativeInteger &other)
 Divides this by the given integer. More...
 
NativeIntegerdivByExact (Native other)
 Divides this by the given integer. More...
 
NativeIntegeroperator%= (const NativeInteger &other)
 Reduces this integer modulo the given integer. More...
 
NativeIntegeroperator%= (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)
 

Detailed Description

template<int bytes>
class regina::NativeInteger< bytes >

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.

Precondition
The system must support integers of the given size; in particular, there must be an appropriate specialisation IntOfSize<bytes>.
Python:\n Not present.

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

Copyright © 1999-2020, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@maths.uq.edu.au).