Arageli::big_int Class Reference

Big integer number. More...

#include <big_int.hpp>

List of all members.

Public Member Functions

 big_int ()
 Constructs a zero.
 big_int (const char *str)
 Converts a string to a big_int.
 big_int (const big_int &b)
 Just a copy constructor (note: there is a link counter).
template<typename T>
 big_int (const rational< T > &x)
 Additional constructor. For GCC compatibility only!!!
bool operator! () const
 Returns true if the number is not zero and false otherwise.
 ~big_int ()
big_intoperator= (const big_int &b)
 Just an assignment (note: there is a link counter).
big_intoperator= (const char *s)
big_intoperator= (char x)
big_intoperator= (signed char x)
big_intoperator= (unsigned char x)
big_intoperator= (signed short x)
big_intoperator= (unsigned short x)
big_intoperator= (signed int x)
big_intoperator= (unsigned int x)
big_intoperator= (signed long int x)
big_intoperator= (unsigned long int x)
big_intoperator= (bool x)
big_intoperator= (float x)
big_intoperator= (double x)
big_intoperator= (long double x)
template<typename T>
big_intoperator= (const rational< T > &x)
std::size_t length () const
 Returns the number of bits in number.
bool operator[] (std::size_t k) const
 Access to specific bit in this number.
int sign () const
 Sign of a number.
bool is_null () const
 Return true if this number is zero.
bool is_unit () const
 Return true if this number is unit.
bool is_opposite_unit () const
 Return true if this number is opposite unit.
const big_intoperator+ () const
 Unary plus.
big_int operator- () const
 Unary minus.
big_intoperator++ ()
 Prefix form of an increment.
big_intoperator-- ()
 Prefix form of a decrement.
big_int operator++ (int)
 Postfix form of an increment.
big_int operator-- (int)
 Postfix form of a decrement.
bool bit (std::size_t k) const
 Returns the k-th bit of the number.
bool is_even () const
 Returns true if even, false if odd.
bool is_odd () const
 Returns true if odd, false if even.
void swap (big_int &x)
 Swaps two numbers.
Initializations from built-in types.
 big_int (char x)
 big_int (signed char x)
 big_int (unsigned char x)
 big_int (signed short x)
 big_int (unsigned short x)
 big_int (signed int x)
 big_int (unsigned int x)
 big_int (signed long int x)
 big_int (unsigned long int x)
 big_int (bool x)
 big_int (float x)
 big_int (double x)
 big_int (long double x)
Convertions to built-in types.
 operator char () const
 operator signed char () const
 operator unsigned char () const
 operator signed short () const
 operator unsigned short () const
 operator signed int () const
 operator unsigned int () const
 operator signed long int () const
 operator unsigned long int () const
 operator bool () const
 operator float () const
 operator double () const
 operator long double () const

Static Public Member Functions

static big_int random_with_length (std::size_t len)
 Returns pseudo-random number with exact len bits.
static big_int random_in_range (const big_int &max)
 Returns pseudo-random number in range [0, max].
static big_int random_with_length_or_less (std::size_t len)
 Returns pseudo-random number with len or less then len bits.

Friends

big_int operator+ (const big_int &b, const big_int &c)
big_int operator- (const big_int &b, const big_int &c)
big_int operator * (const big_int &b, const big_int &c)
big_int operator/ (const big_int &b, const big_int &c)
big_int operator% (const big_int &b, const big_int &c)
big_int operator & (const big_int &b, const big_int &c)
big_int operator| (const big_int &b, const big_int &c)
big_int operator^ (const big_int &b, const big_int &c)
std::ostream & operator<< (std::ostream &s, const big_int &x)
 Reads a number from a string notation.
std::istream & operator>> (std::istream &s, big_int &x)
 Writes a number to a string notation.
int cmp (const big_int &a, const big_int &b)
 Compares two big integers.
void _Internal::xdivide (big_int &a, const big_int &b, const big_int &c, big_int &res)
big_int operator<< (const big_int &a, std::size_t n)
big_int operator>> (const big_int &a, std::size_t n)
big_intoperator>>= (big_int &a, std::size_t n)

Classes

class  exception
 Exception of class big_int. More...
class  incorrect_string
 Exeption. The throwing situation is incorrect format of string. More...


Detailed Description

Big integer number.

Definition at line 72 of file big_int.hpp.


Constructor & Destructor Documentation

Arageli::big_int::big_int (  )  [inline]

Constructs a zero.

After this initialization call of is_null returns true.

Definition at line 118 of file big_int.hpp.

Arageli::big_int::big_int ( const char *  str  ) 

Converts a string to a big_int.

Conversions is based on operator>> for std::istream. See rules for string there.

Parameters:
str a string for initialization

Definition at line 478 of file big_int.cpp.

Arageli::big_int::big_int ( const big_int b  )  [inline]

Just a copy constructor (note: there is a link counter).

Copy constructor actually does not make a copy of number representation. This solution is based on link counter. This constructor just increment link counter and store in this object a pointer to number representation.

Definition at line 130 of file big_int.hpp.

template<typename T>
Arageli::big_int::big_int ( const rational< T > &  x  )  [inline]

Additional constructor. For GCC compatibility only!!!

I do not really know why this is needed for GCC, but... it is needed!!! If you know this, please, email me on sergey.lyalin@gmail.com. Without this constructor compilation of construct from rational will be failed.

Definition at line 145 of file big_int.hpp.

Arageli::big_int::big_int ( char  x  )  [inline]

Definition at line 154 of file big_int.hpp.

Arageli::big_int::big_int ( signed char  x  )  [inline]

Definition at line 155 of file big_int.hpp.

Arageli::big_int::big_int ( unsigned char  x  )  [inline]

Definition at line 156 of file big_int.hpp.

Arageli::big_int::big_int ( signed short  x  )  [inline]

Definition at line 157 of file big_int.hpp.

Arageli::big_int::big_int ( unsigned short  x  )  [inline]

Definition at line 158 of file big_int.hpp.

Arageli::big_int::big_int ( signed int  x  )  [inline]

Definition at line 159 of file big_int.hpp.

Arageli::big_int::big_int ( unsigned int  x  )  [inline]

Definition at line 160 of file big_int.hpp.

Arageli::big_int::big_int ( signed long int  x  )  [inline]

Definition at line 161 of file big_int.hpp.

Arageli::big_int::big_int ( unsigned long int  x  )  [inline]

Definition at line 162 of file big_int.hpp.

Arageli::big_int::big_int ( bool  x  )  [inline]

Definition at line 163 of file big_int.hpp.

Arageli::big_int::big_int ( float  x  )  [inline]

Definition at line 179 of file big_int.hpp.

Arageli::big_int::big_int ( double  x  )  [inline]

Definition at line 180 of file big_int.hpp.

Arageli::big_int::big_int ( long double  x  )  [inline]

Definition at line 181 of file big_int.hpp.

Arageli::big_int::~big_int (  )  [inline]

Definition at line 248 of file big_int.hpp.


Member Function Documentation

bool Arageli::big_int::bit ( std::size_t  k  )  const [inline]

Returns the k-th bit of the number.

Definition at line 388 of file big_int.hpp.

bool Arageli::big_int::is_even (  )  const [inline]

Returns true if even, false if odd.

Definition at line 391 of file big_int.hpp.

bool Arageli::big_int::is_null (  )  const [inline]

Return true if this number is zero.

Definition at line 783 of file big_int.hpp.

bool Arageli::big_int::is_odd (  )  const [inline]

Returns true if odd, false if even.

Definition at line 404 of file big_int.hpp.

bool Arageli::big_int::is_opposite_unit (  )  const [inline]

Return true if this number is opposite unit.

Definition at line 788 of file big_int.hpp.

bool Arageli::big_int::is_unit (  )  const [inline]

Return true if this number is unit.

Definition at line 785 of file big_int.hpp.

std::size_t Arageli::big_int::length (  )  const

Returns the number of bits in number.

Complexity: O(log(n)), where n is the current value of number.

Definition at line 1253 of file big_int.cpp.

Arageli::big_int::operator bool (  )  const [inline]

Definition at line 216 of file big_int.hpp.

Arageli::big_int::operator char (  )  const [inline]

Definition at line 189 of file big_int.hpp.

Arageli::big_int::operator double (  )  const [inline]

Definition at line 239 of file big_int.hpp.

Arageli::big_int::operator float (  )  const [inline]

Definition at line 238 of file big_int.hpp.

Arageli::big_int::operator long double (  )  const [inline]

Definition at line 240 of file big_int.hpp.

Arageli::big_int::operator signed char (  )  const [inline]

Definition at line 192 of file big_int.hpp.

Arageli::big_int::operator signed int (  )  const [inline]

Definition at line 204 of file big_int.hpp.

Arageli::big_int::operator signed long int (  )  const [inline]

Definition at line 210 of file big_int.hpp.

Arageli::big_int::operator signed short (  )  const [inline]

Definition at line 198 of file big_int.hpp.

Arageli::big_int::operator unsigned char (  )  const [inline]

Definition at line 195 of file big_int.hpp.

Arageli::big_int::operator unsigned int (  )  const [inline]

Definition at line 207 of file big_int.hpp.

Arageli::big_int::operator unsigned long int (  )  const [inline]

Definition at line 213 of file big_int.hpp.

Arageli::big_int::operator unsigned short (  )  const [inline]

Definition at line 201 of file big_int.hpp.

bool Arageli::big_int::operator! (  )  const [inline]

Returns true if the number is not zero and false otherwise.

Definition at line 246 of file big_int.hpp.

const big_int& Arageli::big_int::operator+ (  )  const [inline]

Unary plus.

Returns a reference on this object. It does not anything.

Definition at line 323 of file big_int.hpp.

big_int Arageli::big_int::operator++ ( int   )  [inline]

Postfix form of an increment.

Increments this number by 1 and returns an old value of this object.

Definition at line 338 of file big_int.hpp.

big_int& Arageli::big_int::operator++ (  )  [inline]

Prefix form of an increment.

Increments this number by 1 and returns a reference on this object.

Definition at line 330 of file big_int.hpp.

big_int Arageli::big_int::operator- (  )  const

Unary minus.

Definition at line 524 of file big_int.cpp.

big_int Arageli::big_int::operator-- ( int   )  [inline]

Postfix form of a decrement.

Decrements this number by 1 and returns an old value of this object.

Definition at line 342 of file big_int.hpp.

big_int& Arageli::big_int::operator-- (  )  [inline]

Prefix form of a decrement.

Decrements this number by 1 and returns a reference on this object.

Definition at line 334 of file big_int.hpp.

template<typename T>
big_int& Arageli::big_int::operator= ( const rational< T > &  x  )  [inline]

Definition at line 293 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( long double  x  )  [inline]

Definition at line 290 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( double  x  )  [inline]

Definition at line 289 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( float  x  )  [inline]

Definition at line 288 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( bool  x  )  [inline]

Definition at line 272 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( unsigned long int  x  )  [inline]

Definition at line 271 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( signed long int  x  )  [inline]

Definition at line 270 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( unsigned int  x  )  [inline]

Definition at line 269 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( signed int  x  )  [inline]

Definition at line 268 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( unsigned short  x  )  [inline]

Definition at line 267 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( signed short  x  )  [inline]

Definition at line 266 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( unsigned char  x  )  [inline]

Definition at line 265 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( signed char  x  )  [inline]

Definition at line 264 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( char  x  )  [inline]

Definition at line 263 of file big_int.hpp.

big_int& Arageli::big_int::operator= ( const char *  s  )  [inline]

Definition at line 260 of file big_int.hpp.

big_int & Arageli::big_int::operator= ( const big_int b  ) 

Just an assignment (note: there is a link counter).

This assignment operator actually does not make a copy of a number representation. This solution is based on link counter. This operator just decrement a link counter for current representation and increments link counter for a representation of b and store in this object a pointer to number representation of b. Returns a reference on this object.

Parameters:
b a new value

Definition at line 500 of file big_int.cpp.

bool Arageli::big_int::operator[] ( std::size_t  k  )  const

Access to specific bit in this number.

Requirements: 0 <= k < length().

Parameters:
k an address of bit, where k = 0 points to lower bit.

Definition at line 1268 of file big_int.cpp.

big_int Arageli::big_int::random_in_range ( const big_int max  )  [static]

Returns pseudo-random number in range [0, max].

Generating is based on std::rand function. Each number from range [0, max] is equiprobable.

Definition at line 870 of file big_int.cpp.

static big_int Arageli::big_int::random_with_length ( std::size_t  len  )  [inline, static]

Returns pseudo-random number with exact len bits.

Generating is based on std::rand function. Random number in range [2^(len - 1), 2^len - 1]. Each number from range is equiprobable.

Definition at line 363 of file big_int.hpp.

big_int Arageli::big_int::random_with_length_or_less ( std::size_t  len  )  [static]

Returns pseudo-random number with len or less then len bits.

Generating is based on std::rand function. Random number in range [0, 2^len - 1]. Each number from range is equiprobable.

Definition at line 884 of file big_int.cpp.

int Arageli::big_int::sign (  )  const [inline]

Sign of a number.

Returns

Definition at line 310 of file big_int.hpp.

void Arageli::big_int::swap ( big_int x  )  [inline]

Swaps two numbers.

Definition at line 416 of file big_int.hpp.


Friends And Related Function Documentation

void _Internal::xdivide ( big_int a,
const big_int b,
const big_int c,
big_int res 
) [friend]

int cmp ( const big_int a,
const big_int b 
) [friend]

Compares two big integers.

Returns

Definition at line 785 of file big_int.cpp.

big_int operator & ( const big_int b,
const big_int c 
) [friend]

Definition at line 1355 of file big_int.cpp.

big_int operator * ( const big_int b,
const big_int c 
) [friend]

Definition at line 636 of file big_int.cpp.

big_int operator% ( const big_int b,
const big_int c 
) [friend]

Definition at line 762 of file big_int.cpp.

big_int operator+ ( const big_int b,
const big_int c 
) [friend]

Definition at line 550 of file big_int.cpp.

big_int operator- ( const big_int b,
const big_int c 
) [friend]

Definition at line 625 of file big_int.cpp.

big_int operator/ ( const big_int b,
const big_int c 
) [friend]

Definition at line 770 of file big_int.cpp.

big_int operator<< ( const big_int a,
std::size_t  n 
) [friend]

Definition at line 1281 of file big_int.cpp.

std::ostream& operator<< ( std::ostream &  s,
const big_int x 
) [friend]

Reads a number from a string notation.

Definition at line 930 of file big_int.cpp.

big_int operator>> ( const big_int a,
std::size_t  n 
) [friend]

Definition at line 1319 of file big_int.cpp.

std::istream& operator>> ( std::istream &  s,
big_int x 
) [friend]

Writes a number to a string notation.

Definition at line 990 of file big_int.cpp.

big_int& operator>>= ( big_int a,
std::size_t  n 
) [friend]

Definition at line 524 of file big_int.hpp.

big_int operator^ ( const big_int b,
const big_int c 
) [friend]

big_int operator| ( const big_int b,
const big_int c 
) [friend]


The documentation for this class was generated from the following files:
Generated on Thu Aug 31 17:38:22 2006 for Arageli by  doxygen 1.4.7