Canola
0.8.D001
|
#include <z.h>
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_z & | operator= (const number_z &rhs) |
void | clear (void) |
bool | is_zero (void) const |
bool | is_not_zero (void) const |
bool | is_one (void) const |
number_z & | operator+= (const number_z &rhs) |
number_z | operator+ (const number_z &rhs) const |
number_z & | operator-= (const number_z &rhs) |
number_z | operator- (const number_z &rhs) const |
number_z & | operator*= (const number_z &rhs) |
number_z | operator* (const number_z &rhs) const |
number_z & | operator/= (const number_z &rhs) |
number_z | operator/ (const number_z &rhs) const |
number_z & | operator%= (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 "ient, 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_t * | digits |
The number_z class is used to represent an arbitrary precision non-negative number, represented as one BCD digit per byte.
typedef unsigned char number_z::digit_t [private] |
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.
rhs | The right hand side of the initialization. |
Definition at line 24 of file constructor3.cc.
number_z::number_z | ( | unsigned long | rhs | ) |
A constructor.
rhs | The right hand side of the initialization. |
Definition at line 24 of file constructor4.cc.
number_z::number_z | ( | unsigned | rhs | ) |
A constructor.
rhs | The 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.
rhs | The right hand side of the initialization. |
Definition at line 24 of file constructor_copy.cc.
void number_z::build | ( | unsigned | c | ) |
void number_z::clear | ( | void | ) |
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!=).
lhs | The left hand side of the comparison. |
rhs | The right hand side of the comparison. |
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);
numerator | The number above the line in the division. |
denominator | The number below the line in the division. |
quotient | The whole number of times the denominator can be subtracted from the numerator. |
remainder | What 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.
digit_number | The nunber of the digit, starting at 0 for the right hand digit and working rightwards as the digit_number increases. |
size_t number_z::get_digit_count | ( | void | ) | const [inline] |
bool number_z::is_not_zero | ( | void | ) | const [inline] |
bool number_z::is_one | ( | void | ) | const |
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] |
Definition at line 32 of file multiplication.cc.
Definition at line 24 of file multiplication.cc.
Definition at line 41 of file addition.cc.
Definition at line 24 of file addition.cc.
Definition at line 50 of file subtraction.cc.
Definition at line 24 of file subtraction.cc.
Definition at line 22 of file division.cc.
Definition at line 33 of file division.cc.
The assignment operator.
rhs | The right hand side of the assignment. |
Definition at line 24 of file assignment.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] |
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.
ndigits | The number of decimal places to shift by. |
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.
ndigits | The number of decimal places to shift by. |
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.
digit_t* number_z::digits [private] |
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.
size_t number_z::digits_allocated [private] |
size_t number_z::digits_used [private] |