LongInt< BITS, MAY_OVERFLOW > Class Template Reference

#include <LongInt.h>

List of all members.

Public Types

enum  
typedef unsigned short block_type
typedef unsigned long double_block
typedef LongInt< BITS, MAY_OVERFLOW > long_type

Public Member Functions

 LongInt ()
 LongInt (const LongInt &other)
long_typeoperator= (const LongInt &other)
 LongInt (int u)
 LongInt (double_block u)
 LongInt (const char *psz, unsigned int nBase=10)
long_typecomplement2 ()
long_type operator- () const
long_typeoperator+= (const long_type &v)
long_type operator+ (const long_type &v) const
long_typeoperator-= (const long_type &v)
long_type operator- (const long_type &v) const
bool isNegative () const
long_typeoperator *= (long_type v)
long_type operator * (const long_type &v)
long_typeoperator/= (const long_type &d)
long_type operator/ (const long_type &d) const
long_typeoperator%= (const long_type &d)
long_type operator% (const long_type &d) const
long_type divide (long_type v, long_type *pRem=0, bool bSigned=true) const
bool operator! () const
int compare (const long_type &v) const
bool operator< (const long_type &v) const
bool operator<= (const long_type &v) const
bool operator== (const long_type &v) const
bool operator!= (const long_type &v) const
std::string toString (unsigned int nBase=10) const
void display (std::ostream &os=std::cout) const
void load (std::istream &is)
void save (std::ostream &os) const
long_typefromString (const char *psz, unsigned int nBase=10)
long_type operator<< (int n) const
long_typeoperator<<= (int u)
long_type operator>> (int n) const
LongIntoperator>>= (int u)
long_type operator & (const long_type &v) const
long_typeoperator &= (const long_type &u)
long_type operator| (const long_type &v) const
long_typeoperator|= (const long_type &u)
long_type operator^ (const long_type &v) const
long_typeoperator^= (const long_type &u)

Friends

std::ostream & operator<< (std::ostream &os, const long_type &x)
std::istream & operator>> (std::istream &is, long_type &x)


Detailed Description

template<unsigned int BITS, bool MAY_OVERFLOW = false>
class LongInt< BITS, MAY_OVERFLOW >

LongInt Represents an extended precision, signed integer. All the operations that you can do with a usual int you can also do with a LongInt. Additionally the LongInt class provides conversions to/from strings and all methods that are common to the math objects from this math library. The precision of LongInt is fixed and is established at compile time by means of its template parameter

Definition at line 39 of file LongInt.h.


Constructor & Destructor Documentation

template<unsigned int BITS, bool MAY_OVERFLOW = false>
LongInt< BITS, MAY_OVERFLOW >::LongInt (  )  [inline]

Default constructor

Remarks:
Does nothing.

Definition at line 58 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
LongInt< BITS, MAY_OVERFLOW >::LongInt ( const LongInt< BITS, MAY_OVERFLOW > &  other  )  [inline]

Copy constructor

other Value assigned to this LongInt

Definition at line 65 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::m_data.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
LongInt< BITS, MAY_OVERFLOW >::LongInt ( int  u  )  [inline]

Constructor

u signed integer to initialize this LongInt with

Definition at line 87 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
LongInt< BITS, MAY_OVERFLOW >::LongInt ( const char *  psz,
unsigned int  nBase = 10 
) [inline, explicit]

Constructor

psz The string representation of a large integer
nBase The numeration base that the string is using to represent the
number in the range [2, 36] inclusive.
Remarks:
The number format is [-+]digits. If invalid characters are found a math_exception is thrown.

Definition at line 114 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::fromString().

Here is the call graph for this function:


Member Function Documentation

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator= ( const LongInt< BITS, MAY_OVERFLOW > &  other  )  [inline]

Assignment operator

other Value assigned to this LongInt
Returns:
A refference to this LongInt

Definition at line 74 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::m_data.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::complement2 (  )  [inline]

Unary minus or two's complement

Returns:
A refference to this LongInt
Remarks:
Tramsforms this LongInt to -(minus) (this LongInt)

Definition at line 123 of file LongInt.h.

Referenced by LongInt< BITS, MAY_OVERFLOW >::divide(), LongInt< BITS, MAY_OVERFLOW >::fromString(), and LongInt< BITS, MAY_OVERFLOW >::operator *=().

Here is the caller graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator- (  )  const [inline]

Unary minus operator

Definition at line 151 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator+= ( const long_type v  )  [inline]

Addition assignment operator

v Right hand side operand
Returns:
A refference to this LongInt
Remarks:
If the MAY_OVERFLOW template parameter is true, this operator will throw an exception if an overflow occurs.

Definition at line 162 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::m_data.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator+ ( const long_type v  )  const [inline]

Addition operator

v Right hand side operand
Returns:
The result of the operation
Remarks:
If the MAY_OVERFLOW template parameter is true, this operator will throw an exception if an overflow occurs.

Definition at line 210 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator-= ( const long_type v  )  [inline]

Subtraction assignment operator

v Right hand side operand
Returns:
A refference to this LongInt
Remarks:
If the MAY_OVERFLOW template parameter is true, this operator will throw an exception if an overflow occurs.

Definition at line 221 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::m_data.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator- ( const long_type v  )  const [inline]

Subtraction operator

v Right hand side operand
Returns:
The result of the operation.
Remarks:
If the MAY_OVERFLOW template parameter is true, this operator will throw an exception if an overflow occurs.

Definition at line 272 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
bool LongInt< BITS, MAY_OVERFLOW >::isNegative (  )  const [inline]

Determine if this LongInt is negative

Returns:
true if this is less than zero and false otherwise

Definition at line 280 of file LongInt.h.

Referenced by LongInt< BITS, MAY_OVERFLOW >::compare(), LongInt< BITS, MAY_OVERFLOW >::divide(), LongInt< BITS, MAY_OVERFLOW >::operator *=(), LongInt< BITS, MAY_OVERFLOW >::operator>>(), and LongInt< BITS, MAY_OVERFLOW >::toString().

Here is the caller graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator *= ( long_type  v  )  [inline]

Multiplication assignment operator

v Right hand side operand
Returns:
A refference to this LongInt
Remarks:
If the MAY_OVERFLOW template parameter is true, this operator will throw an exception if an overflow occurs.

Definition at line 292 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::complement2(), LongInt< BITS, MAY_OVERFLOW >::isNegative(), and LongInt< BITS, MAY_OVERFLOW >::m_data.

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator * ( const long_type v  )  [inline]

Multiplication operator

v Right hand side operand
Returns:
The result of the operation
Remarks:
If the MAY_OVERFLOW template parameter is true, this operator will throw an exception if an overflow occurs.

Definition at line 397 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator/= ( const long_type d  )  [inline]

Division assignment operator

Parameters:
d the dividend
Returns:
A refference to this LongInt
Remarks:
In order to find the reminder also use the method divide, it is more efficient that way.

Definition at line 408 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::divide().

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator/ ( const long_type d  )  const [inline]

Division operator

Parameters:
d the dividend
Returns:
The quotient from the division
Remarks:
In order to find the reminder also use the method divide, it is more efficient that way.

Definition at line 420 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::divide().

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator%= ( const long_type d  )  [inline]

Modulo assignment operator

Parameters:
d the dividend
Returns:
A refference to this LongInt
Remarks:
In order to find the quotient also use the method divide, it is more efficient that way.

Definition at line 431 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::divide().

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator% ( const long_type d  )  const [inline]

Modulo operator

Parameters:
d the dividend
Returns:
The reminder from the division
Remarks:
In order to find the quotient also use the method divide, it is more efficient that way.

Definition at line 443 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::divide().

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::divide ( long_type  v,
long_type pRem = 0,
bool  bSigned = true 
) const [inline]

Compute the quotient and remainder of (this / v)

Precondition:
v must be different from zero or else a division by zero exception will be thrown
Parameters:
v The divisor
[out] pRem If not null, this parameter will contain the remainder
bSigned This should be always be true since LongInts are signed by default, if this parameter is false the LongInts are considered unsigned
Remarks:
This algorithm is based on "The Art of Computer Programming", volume 2, D. Knuth, Section 4.3.1, Algorithm D and exercise 16.

Definition at line 461 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::compare(), LongInt< BITS, MAY_OVERFLOW >::complement2(), LongInt< BITS, MAY_OVERFLOW >::isNegative(), and LongInt< BITS, MAY_OVERFLOW >::m_data.

Referenced by LongInt< BITS, MAY_OVERFLOW >::operator%(), LongInt< BITS, MAY_OVERFLOW >::operator%=(), LongInt< BITS, MAY_OVERFLOW >::operator/(), LongInt< BITS, MAY_OVERFLOW >::operator/=(), and LongInt< BITS, MAY_OVERFLOW >::toString().

Here is the call graph for this function:

Here is the caller graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
bool LongInt< BITS, MAY_OVERFLOW >::operator! (  )  const [inline]

Test if a LongInt is different from zero

Returns:
true if this is different from zero and false otherwise

Definition at line 807 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
int LongInt< BITS, MAY_OVERFLOW >::compare ( const long_type v  )  const [inline]

Compare two LongInt-s

Parameters:
v The second operand
Returns:
0 if numbers are equal, -1 if this is less than v and 1 if v is less than this.

Definition at line 825 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::isNegative(), and LongInt< BITS, MAY_OVERFLOW >::m_data.

Referenced by LongInt< BITS, MAY_OVERFLOW >::divide(), AlgebraicTraits< LongInt< BITS, MAY_OVERFLOW > >::equals(), LongInt< BITS, MAY_OVERFLOW >::operator!=(), LongInt< BITS, MAY_OVERFLOW >::operator<(), LongInt< BITS, MAY_OVERFLOW >::operator<=(), and LongInt< BITS, MAY_OVERFLOW >::operator==().

Here is the call graph for this function:

Here is the caller graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
bool LongInt< BITS, MAY_OVERFLOW >::operator< ( const long_type v  )  const [inline]

Less than operator

Parameters:
v Right hand side operand
Returns:
true if this is less than right hand side operand

Definition at line 855 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::compare().

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
bool LongInt< BITS, MAY_OVERFLOW >::operator<= ( const long_type v  )  const [inline]

Less than or equal operator

Parameters:
v Right hand side operand
Returns:
true if this is less than or equal to the right hand side operand

Definition at line 864 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::compare().

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
bool LongInt< BITS, MAY_OVERFLOW >::operator== ( const long_type v  )  const [inline]

Equality operator

Parameters:
v Right hand side operand
Returns:
true if this is equal to the right hand side operand

Definition at line 873 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::compare().

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
bool LongInt< BITS, MAY_OVERFLOW >::operator!= ( const long_type v  )  const [inline]

Inequality operator

Parameters:
v Right hand side operand
Returns:
true if this is different than the right hand side operand

Definition at line 882 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::compare().

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
std::string LongInt< BITS, MAY_OVERFLOW >::toString ( unsigned int  nBase = 10  )  const [inline]

Convert to string

Parameters:
nBase The base to convert to, this can be between 2 and 36 inclusive
Returns:
The result of the conversion

Definition at line 892 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::divide(), LongInt< BITS, MAY_OVERFLOW >::isNegative(), and LongInt< BITS, MAY_OVERFLOW >::toLong().

Referenced by LongInt< BITS, MAY_OVERFLOW >::display().

Here is the call graph for this function:

Here is the caller graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
void LongInt< BITS, MAY_OVERFLOW >::display ( std::ostream &  os = std::cout  )  const [inline]

Display this number to a stream

os The stream to display to.
Remarks:
You can use operator<<(std::ostream&, LongInt&) instead

Definition at line 998 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::toString().

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
void LongInt< BITS, MAY_OVERFLOW >::load ( std::istream &  is  )  [inline]

Load this number from a stream

Parameters:
is stream to load from

Definition at line 1007 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
void LongInt< BITS, MAY_OVERFLOW >::save ( std::ostream &  os  )  const [inline]

Save this number to a stream

Parameters:
os stream to save to

Definition at line 1016 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::fromString ( const char *  psz,
unsigned int  nBase = 10 
) [inline]

Initializes this LongInt from a string number representation

psz The string representation of a large integer
nBase The numeration base that the string is using to represent the
number in the range [2, 36] inclusive.
Remarks:
The number format is [-+]digits. If invalid characters are found a math_exception is thrown.

Definition at line 1029 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::complement2(), and math_exception::what().

Referenced by LongInt< BITS, MAY_OVERFLOW >::LongInt().

Here is the call graph for this function:

Here is the caller graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator<< ( int  n  )  const [inline]

Left shift operator

Parameters:
n The number of bits to shift to the left
Returns:
This number shifted to the left with n bytes

Definition at line 1113 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::m_data.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator<<= ( int  u  )  [inline]

Left shift assignment operator

Parameters:
u The number of bits to shift to the left
Returns:
A refference to this LongInt

Definition at line 1178 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator>> ( int  n  )  const [inline]

Right shift operator

Parameters:
n The number of bits to shift to the right
Returns:
This number shifted to the left with n bytes

Definition at line 1187 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::isNegative(), and LongInt< BITS, MAY_OVERFLOW >::m_data.

Here is the call graph for this function:

template<unsigned int BITS, bool MAY_OVERFLOW = false>
LongInt& LongInt< BITS, MAY_OVERFLOW >::operator>>= ( int  u  )  [inline]

Right shift assignment operator

Parameters:
u The number of bits to shift to the right
Returns:
A refference to this LongInt

Definition at line 1237 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator & ( const long_type v  )  const [inline]

Binary And operator

Parameters:
v Right hand side operand
Returns:
The result of the operation

Definition at line 1246 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::m_data.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator &= ( const long_type u  )  [inline]

Binary And assignment operator

Parameters:
u Right hand side operand
Returns:
A refference to this LongInt

Definition at line 1260 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator| ( const long_type v  )  const [inline]

Binary Or operator

Parameters:
v Right hand side operand
Returns:
The result of the operation

Definition at line 1269 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::m_data.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator|= ( const long_type u  )  [inline]

Binary Or assignment operator

Parameters:
u Right hand side operand
Returns:
A refference to this LongInt

Definition at line 1284 of file LongInt.h.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type LongInt< BITS, MAY_OVERFLOW >::operator^ ( const long_type v  )  const [inline]

Binary Xor operator

Parameters:
v Right hand side operand
Returns:
The result of the operation

Definition at line 1293 of file LongInt.h.

References LongInt< BITS, MAY_OVERFLOW >::m_data.

template<unsigned int BITS, bool MAY_OVERFLOW = false>
long_type& LongInt< BITS, MAY_OVERFLOW >::operator^= ( const long_type u  )  [inline]

Binary Xor assignment operator

Parameters:
u Right hand side operand
Returns:
A refference to this LongInt

Definition at line 1308 of file LongInt.h.


The documentation for this class was generated from the following file:
Math-Objects Library Docs  Generated by: doxygen