Canola  0.8.D001
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
number_z Class Reference

#include <z.h>

List of all members.

Public Member Functions

 ~number_z ()
 number_z ()
 number_z (unsigned long long rhs)
 number_z (unsigned long rhs)
 number_z (unsigned rhs)
 number_z (const number_z &rhs)
number_zoperator= (const number_z &rhs)
void clear (void)
bool is_zero (void) const
bool is_not_zero (void) const
bool is_one (void) const
number_zoperator+= (const number_z &rhs)
number_z operator+ (const number_z &rhs) const
number_zoperator-= (const number_z &rhs)
number_z operator- (const number_z &rhs) const
number_zoperator*= (const number_z &rhs)
number_z operator* (const number_z &rhs) const
number_zoperator/= (const number_z &rhs)
number_z operator/ (const number_z &rhs) const
number_zoperator%= (const number_z &rhs)
number_z operator% (const number_z &rhs) const
number_z shift_left (size_t ndigits) const
number_z shift_right (size_t ndigits) const
bool operator< (const number_z &rhs) const
bool operator<= (const number_z &rhs) const
bool operator> (const number_z &rhs) const
bool operator>= (const number_z &rhs) const
bool operator== (const number_z &rhs) const
bool operator!= (const number_z &rhs) const
unsigned get (size_t digit_number) const
size_t get_digit_count (void) const
number_z right_16 (void) const
std::string representation (void) const
void print_me (const char *file, int line, const char *caption) const
void build (unsigned c)
long to_long (void) const

Static Public Member Functions

static number_z one (void)

Private Types

typedef unsigned char digit_t

Private Member Functions

bool is_valid (void) const
void set (size_t dignum, unsigned digval)

Static Private Member Functions

static bool div_mod (const number_z &numerator, const number_z &denominator, number_z &quotient, number_z &remainder)
static int compare (const number_z &lhs, const number_z &rhs)

Private Attributes

size_t digits_used
size_t digits_allocated
digit_tdigits

Detailed Description

The number_z class is used to represent an arbitrary precision non-negative number, represented as one BCD digit per byte.

Definition at line 28 of file z.h.


Member Typedef Documentation

typedef unsigned char number_z::digit_t [private]

Definition at line 218 of file z.h.


Constructor & Destructor Documentation

The destructor. It is not virtual, thou shalt not derive from this class.

Definition at line 21 of file z.cc.

The default constructor. The value will be zero.

Definition at line 23 of file constructor_default.cc.

number_z::number_z ( unsigned long long  rhs)

A constructor.

Parameters:
rhsThe right hand side of the initialization.

Definition at line 24 of file constructor3.cc.

number_z::number_z ( unsigned long  rhs)

A constructor.

Parameters:
rhsThe right hand side of the initialization.

Definition at line 24 of file constructor4.cc.

number_z::number_z ( unsigned  rhs)

A constructor.

Parameters:
rhsThe right hand side of the initialization.

Definition at line 24 of file constructor2.cc.

number_z::number_z ( const number_z rhs)

The copy constructor.

Parameters:
rhsThe right hand side of the initialization.

Definition at line 24 of file constructor_copy.cc.


Member Function Documentation

void number_z::build ( unsigned  c)

The build method is used when building number from left to right, e.g. in a lexical analyzer. The number is shifted left on decimal place, and the given digits is made the least significant decimal digit.

Parameters:
cThe digit to be added on the right.

Definition at line 24 of file build.cc.

void number_z::clear ( void  )

Definition at line 25 of file clear.cc.

int number_z::compare ( const number_z lhs,
const number_z rhs 
) [static, private]

The compare class method is used to determine the relationship between two integers. This helper method is used to the relational operators ( operator<, operator<=, operator>, operator>=, operator== and operator!=).

Parameters:
lhsThe left hand side of the comparison.
rhsThe right hand side of the comparison.
Returns:
<0 if lhs is less than rhs, 0 if lhs is equal to rhs >0 if lhs is greather than rhs

Definition at line 24 of file compare.cc.

bool number_z::div_mod ( const number_z numerator,
const number_z denominator,
number_z quotient,
number_z remainder 
) [static, private]

The div_mod method is used by the operator/ and operator% methods to perform the calculation.

assert(quotient * denominator + remainder == numerator);

Parameters:
numeratorThe number above the line in the division.
denominatorThe number below the line in the division.
quotientThe whole number of times the denominator can be subtracted from the numerator.
remainderWhat is left over after the numerator is done.

Definition at line 24 of file div_mod.cc.

unsigned number_z::get ( size_t  digit_number) const

The get method is used to get the value of the digit, specified by an index.

Parameters:
digit_numberThe nunber of the digit, starting at 0 for the right hand digit and working rightwards as the digit_number increases.
Returns:
The value of the digit (0..9), or 0 if you are requesting a digit beyond the most significant digit available. This is not in ASCII.

Definition at line 22 of file get.cc.

size_t number_z::get_digit_count ( void  ) const [inline]

Definition at line 165 of file z.h.

bool number_z::is_not_zero ( void  ) const [inline]

Definition at line 87 of file z.h.

bool number_z::is_one ( void  ) const

Definition at line 24 of file is_one.cc.

bool number_z::is_valid ( void  ) const [private]

The is_value method is used to determine whether or not the internal representation of the BCD integer is self-consistent.

Definition at line 22 of file is_valid.cc.

bool number_z::is_zero ( void  ) const

Definition at line 24 of file is_zero.cc.

number_z number_z::one ( void  ) [static]

The one class method is used to obtain a constant 1 value, for use in expressions. This avoid the ambiguity warnings from the compiler.

Definition at line 22 of file one.cc.

bool number_z::operator!= ( const number_z rhs) const

Definition at line 22 of file ne.cc.

number_z number_z::operator% ( const number_z rhs) const

Definition at line 22 of file modulo.cc.

number_z & number_z::operator%= ( const number_z rhs)

Definition at line 33 of file modulo.cc.

number_z number_z::operator* ( const number_z rhs) const

Definition at line 32 of file multiplication.cc.

number_z & number_z::operator*= ( const number_z rhs)

Definition at line 24 of file multiplication.cc.

number_z number_z::operator+ ( const number_z rhs) const

Definition at line 41 of file addition.cc.

number_z & number_z::operator+= ( const number_z rhs)

Definition at line 24 of file addition.cc.

number_z number_z::operator- ( const number_z rhs) const

Definition at line 50 of file subtraction.cc.

number_z & number_z::operator-= ( const number_z rhs)

Definition at line 24 of file subtraction.cc.

number_z number_z::operator/ ( const number_z rhs) const

Definition at line 22 of file division.cc.

number_z & number_z::operator/= ( const number_z rhs)

Definition at line 33 of file division.cc.

bool number_z::operator< ( const number_z rhs) const

Definition at line 22 of file lt.cc.

bool number_z::operator<= ( const number_z rhs) const

Definition at line 22 of file le.cc.

number_z & number_z::operator= ( const number_z rhs)

The assignment operator.

Parameters:
rhsThe right hand side of the assignment.

Definition at line 24 of file assignment.cc.

bool number_z::operator== ( const number_z rhs) const

Definition at line 22 of file eq.cc.

bool number_z::operator> ( const number_z rhs) const

Definition at line 22 of file gt.cc.

bool number_z::operator>= ( const number_z rhs) const

Definition at line 22 of file ge.cc.

void number_z::print_me ( const char *  file,
int  line,
const char *  caption 
) const

Definition at line 24 of file print_me.cc.

std::string number_z::representation ( void  ) const

Definition at line 22 of file representation.cc.

number_z number_z::right_16 ( void  ) const

The right_16 method is used to contruct a new numer from this one, using only the right-most 16 digits, and ignoring any further to the left.

Definition at line 22 of file right_16.cc.

void number_z::set ( size_t  dignum,
unsigned  digval 
) [private]

The set method is used to set a specific decimal digit to a specific decimal value.

Parameters:
dignumThe digit number; 0 is on the rights, more significant digits have larger numbers.
digvalThe value of the digits, always in the range 0..9

Definition at line 26 of file set.cc.

number_z number_z::shift_left ( size_t  ndigits) const

The shift_left method is used to shift the number the given number of decimal digits to the left. Zeros will be shifted into the vacated positions.

Parameters:
ndigitsThe number of decimal places to shift by.
Note:
We do not overload the << operator, because it is for shifting binary bits, whereas this method shifts by decimal places.

Definition at line 25 of file shift_left.cc.

number_z number_z::shift_right ( size_t  ndigits) const

The shift_right method is used to shift the number the given number of decimal digits to the right. Digits on the right are lost.

Parameters:
ndigitsThe number of decimal places to shift by.
Note:
We do not overload the >> operator, because it is for shifting binary bits, whereas this method shifts by decimal places.

Definition at line 25 of file shift_right.cc.

long number_z::to_long ( void  ) const

The to_long method is used to obtaim a C long representation of the value. If it is too big, LONG_MAX will be returned.

Definition at line 24 of file to_long.cc.


Member Data Documentation

The digits instance variable is used to remember the base address of a dynamically allocated array of digits. It grows exponentially, so that set is an O(1) operation.

assert(!digits == !digits_allocated);

The digits between digits_used and digits_allocated are explicitly set to zero.

Definition at line 230 of file z.h.

size_t number_z::digits_allocated [private]

The digits_allocated instance variable is used to remember the number of digits that have been dynamically allocated for the digits array.

Definition at line 216 of file z.h.

size_t number_z::digits_used [private]

The digits_used instance variable is used to remember the number of used positions in the digits array.

assert(digits_used <= digits_allocated);

Definition at line 209 of file z.h.


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