This constructor creates a
This constructor creates a
Warning:
Be sure that the magnitude of any new
This copy constructor creates a
Creates a
Creates a
It is imporant for the internal consistency of the library that
operations always be done on
Returns a non-zero
Strips the lead zeros, if any, from the calling instance's magnitude
and adjusts the size accordingly.
Returns an integer representing the calling instance's sign.
(See the Internal Representation of
Sets the sign of the calling instance equal to the value given by
Returns an integer representing the calling instance's size.
Sets the integer representing the number of digits in the calling
instance's magnitude equal to the value given by
Returns a pointer to the calling instance's magnitude.
Makes the calling instance represent an integer equal to
the integer represented by
Returns a new
Returns a new
Returns a new
Makes the calling instance represent the sum of the integer it represents
before the call and the integer
Makes the calling instance represent the integer one greater than
the integer it represented before the call.
Returns a reference to the modified calling instance.
Makes the calling instance represent the integer one greater than
the integer it represented before the call.
Returns a reference to the modified calling instance.
(Where have I heard this before? :) )
Returns a new
Makes the calling instance represent the the integer it represents
before the call minus the integer
Makes the calling instance represent the integer one less than
the integer it represented before the call.
Returns a reference to the modified calling instance.
Makes the calling instance represent the integer one less than
the integer it represented before the call.
Returns a reference to the modified calling instance.
(Sound famaliar? :) )
Returns a new
Makes the calling instance represent the product of the integer it represents
before and the integer that
From number theory, it is know that given two integers
Makes the calling instance represent the integer the return
value of
From number theory, it is known that given two integers
Makes the calling instance represent the integer the return
value of
Returns a new
Note: under current implementation,
Makes the calling instance represent the integer the return
value of
Note: under current implementation, the calling instance
and
Returns a new
Note: under current implementation,
Makes the calling instance represent the integer the return
value of
Note: under current implementation, the calling instance
and
Returns a new
Note: under current implementation,
Makes the calling instance represent the integer the return
value of
Note: under current implementation, the calling instance
and
Returns a new
Returns a new
Note: Under this implementation,
Makes the calling instance represent the integer the return
value of
Note: the same notes as for
Returns a new
Note: Under this implementation,
Makes the calling instance represent the integer the return
value of
Note: the same notes as for
Returns a non-zero
Returns a non-zero
Returns a non-zero
Returns a non-zero
Returns a non-zero
Returns a non-zero
Returns a non-zero
Returns a non-zero
Returns a non-zero
Returns an
Pushes #include "linteger.hxx"
Constructors
The Default Constructor
LInteger()
LInteger with "NULL" magnitude.
(This is not equivalent to zero magnitude in this library.) Be
careful to assign a magnitude to the returned LInteger
before using it other than as an lvalue.
A Constructor From Magnitude and Sign
LInteger::LInteger(const unsigned int* magnitude,
const int numDigits, const int sign=0, const int copyMag=1)
LInteger
representing the number determined by the first three arguments.
(See the Internal Representation of
LIntegers section for details on the
required format.)
If copyMag is non-zero the new instance will make its own
copy of the magnitude, so that the caller may retain ownership of the
memory pointed to by magnitude. If copyMag
is zero, the library will assume control of the memory, and will attempt
to delete the memory pointed to by mangnitude upon
destruction of the new instance.
LInteger you create with this
constructor does not have lead zeroes. This is necessary for the
internal consistency of the library. If you don't feel like
checking if the magnitude you use has lead zeroes or not, call
compress() immediately after creation of the new instance.
A Copy Constructor from other
LIntegers
LInteger::LInteger(const LInteger& a)
LInteger which represents
the same integer that a does.
A Consturctor from
unsigned ints
LInteger::LInteger(const unsigned int mag, const int sign=0)
LInteger of single digit magnitude whose
sign is determined by the sign argument.
(See the Internal Representation of
LIntegers section for details on the
required value.)
A Constructor from
ints
LInteger::LInteger(const int mag)
LInteger representing the same integer
that mag represents.
Public Methods
Compression Methods
LIntegers with no
lead zeros in their magnitude. The two methods below are included to
help programmers insure that a LInteger has no lead zeros.
Normally, they will not need to be called, however, since
all overloaded operators ensure that the instances they return
or modify have no lead zeros.
compressable
inline int LInteger::compressable() const;
int iff the calling instance
has lead zeros in its magnitude.
compress
void LInteger::compress()
Protected Member Access Methods
sign
inline int LInteger::sign() const
LIntegers section for details on the
required value.)
setSign
inline void LInteger::setSign(const int newSign)
newSign.
size
inline int LInteger::size() const
setSize
inline void LInteger::setSize(const int newSize)
newSize.
magnitude
inline unsigned int* LInteger::magnitude() const
Overloaded Operators
Assignment from a
LInteger: a=b
LInteger& LInteger::operator=(const LInteger& a)
a and returns a
reference to the modified calling instance.
Unary Minus:
-a
friend inline LInteger operator-(const LInteger& a)
LInteger representing the proudct of
-1 and the integer represented by a.
Unary Plus:
+a
friend inline LInteger operator+(const LInteger& a)
LInteger representing the
same integer that a represents. *snore*
Add:
a+b
friend LInteger operator+(const LInteger& a , const LInteger& b)
LInteger representing the sum of the
integers represented by a and b.
Plus Equals:
a+=b
inline LInteger& LInteger::operator+=(const LInteger& b)
b represents.
Returns a reference to the modified calling instance.
Postfix Increment:
a++
inline LInteger& LInteger::operator++(int) // postfix
Prefix Increment:
++a
inline LInteger& LInteger::operator++() // postfix
Minus:
a-b
friend LInteger operator-(const LInteger& a , const LInteger& b)
LInteger representing the
integer represented by a minus
the integer represneted by b.
Minus Equals:
a-=b
inline LInteger& LInteger::operator-=(const LInteger& b)
b represents.
Returns a reference to the modified calling instance.
Postfix Decrement:
a--
inline LInteger& LInteger::operator--(int)
Prefix Decrement:
--a
inline LInteger& LInteger::operator--()
Multiply:
a*b
friend LInteger operator*(const LInteger& a , const LInteger& b)
LInteger representing the product of the
integer represented by a and the integer represneted
by b.
Times Equals:
a*=b
inline LInteger& LInteger::operator*=(const LInteger& b)
b represents.
Returns a reference to the modified calling instance.
Div:
a/b
friend LInteger operator/(const LInteger& a , const LInteger& b)
a
and b such that b is not zero, there exists
q and r such that a=q*b+rwith
0<=r<|b|. a/b returns a
LInteger
representing the integer q given by this theorem.
Div Equals:
a/=b
inline LInteger& LInteger::operator/=(const LInteger& b)
a/b would represent
(see directly above),
and returns a reference to the modified calling instance.
Mod:
a%b
friend LInteger operator%(const LInteger& a , const LInteger& b)
a
and b such that b is not zero, there exists
q and r such that a=q*b+r and
0<=r<|b|. a%b returns a LInteger
representing the integer r given by this theorem.
Mod Equals:
a%=b
inline LInteger& LInteger::operator%=(const LInteger& b)
a%b would represent
(see directly above),
and returns a reference to the modified calling instance.
Exclusive OR:
a^b
friend LInteger operator^(const LInteger& a, const LInteger& b)
LIntegers representing the
integer whose ith most
significant bit is equal to exclusive OR of the ith
most significant bit of the integer represented by a
and the ith most significant bit of the integer
represented by b.
a and
b must represent non-negative integers with
the same number of digits in their magnitude.
Exclusive OR Equals:
a^=b
inline LInteger& LInteger::operator^=(const LInteger& b)
a^b would represent
(see directly above).
Returns a reference to the modified calling instance.
b must both represent non-negative integers with
the same number of digits in their magnitude.
Inclusive OR:
a|b
friend LInteger operator|(const LInteger& a, const LInteger& b)
LIntegers representing the
integer whose ith most
significant bit is equal to inclusive OR of the ith
most significant bit of the integer represented by a
and the ith most significant bit of the integer
represented by b.
a and
b must represent non-negative integers with
the same number of digits in their magnitude.
Inclusive OR Equals:
a|=b
inline LInteger& LInteger::operator|=(const LInteger& b)
a|b would represent
(see directly above).
Returns a reference to the modified calling instance.
b must both represent non-negative integers with
the same number of digits in their magnitude.
AND:
a&b
friend LInteger operator&(const LInteger& a, const LInteger& b)
LIntegers representing the
integer whose ith most
significant bit is equal to the logical conjuction of the ith
most significant bit of the integer represented by a
and the ith most significant bit of the integer
represented by b.
a and
b must represent non-negative integers with
the same number of digits in their magnitude.
AND Equals:
a&=b
inline LInteger& LInteger::operator&=(const LInteger& b)
a&b would represent
(see directly above).
Returns a reference to the modified calling instance.
b must both represent non-negative integers with
the same number of digits in their magnitude.
Bitwise Negate:
~a
friend LInteger operator~(const LInteger& a)
LInteger representing the
integer whose ith most significant bit is
the logical negation of the ith
most singficant bit of the integer represent by a.
Shift Right:
a>>distance
friend LInteger operator>>(const LInteger& a, const int distance)
LInteger representing the integer
whose ith most significant bit is equal to the
i+distanceth most significant bit of the integer
represented by a.
distance can be much greater than
the number of bits in an unsigned int.
distance must
be non-negative.
Shift Right Equals:
a>>=distance
inline LInteger& LInteger::operator>>=(const int distance)
a>>distance would represent
(see directly above).
Returns a reference to the modified calling instance.
>> apply.
(See directly above.).
Shift Left:
a<<distance
friend LInteger operator<<(const LInteger& a, const int distance)
LInteger representing the integer
whose ith least significant bit is equal to the
i-distanceth least significant bit of the integer
represented by a. If i-distance is
not positive, the ith bit of the integer represented
by returned LInteger will be zero.
distance can be much greater than
the number of bits in an unsigned int.
distance must
be non-negative.
Shift Left Equals:
a<<=distance
inline LInteger& LInteger::operator<<=(const int distance)
a<<distance would represent
(see directly above).
Returns a reference to the modified calling instance.
<< apply.
(See directly above.).
Less Than:
a<b
friend inline int operator<(const LInteger& a, const LInteger& b)
int iff a is less than
b.
Greater Than:
a>b
friend inline int operator>(const LInteger& a, const LInteger& b)
int iff a is greater than
b.
Equal To:
a==b
friend inline int operator==(const LInteger& a, const LInteger& b)
int iff a is equal to
b.
Not Equal To:
a!=b
friend inline int operator!=(const LInteger& a, const LInteger& b)
int iff a is not equal to
b.
Less Than Or Equal To:
a<=b
friend inline int operator<=(const LInteger& a, const LInteger& b)
int iff a is less than
or equal to b.
Greater Than Or Equal To:
a>=b
friend inline int operator>=(const LInteger& a, const LInteger& b)
int iff a is greater than
or equal to b.
Logical Negation:
!a
friend inline int operator!(const LInteger& a)
int iff a is non-zero.
Logical Conjuction:
a&&b
friend inline int operator&&(const LInteger& a,const int b)
friend inline int operator&&(const int a,const LInteger& b)
int iff both of the arguments
are non-zero.
Logical Disjunction:
a||b
friend inline int operator||(const LInteger& a,const int b)
friend inline int operator||(const int a,const LInteger& b)
int iff at least one of the arguments
is non-zero.
int Conversion: int(a)
inline LInteger::operator int()
int with the same sign as the calling instance,
and with magnitude equal to the (bits per unsigned int)-1
least significant bits of the calling instance's magnitude.
Stream Output:
s<<a
friend ostream& operator<<(ostream& s, const LInteger& a)
a onto the stream as follows: First, a '-' is
pushed onto the stream if a is negative, otherwise a
'+' is pushed onto the stream. The magnitude of a
in hexadecimal is then pushed onto the stream.
Next
Previous
Table of Contents