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

#include <number.h>

List of all members.

Public Member Functions

 ~number ()
 number ()
 number (const number &rhs)
 number (long rhs)
numberoperator= (const number &rhs)
void operator+= (const number &rhs)
number operator+ (const number &rhs) const
void operator-= (const number &rhs)
number operator- (const number &rhs) const
number operator- (void) const
void operator*= (const number &rhs)
number operator* (const number &rhs) const
void operator/= (const number &rhs)
number operator/ (const number &rhs) const
number sqrt (void) const
long to_long (void) const
number round_up (int preferred_decimal) const
number round_off (int preferred_decimal) const
number round_down (int preferred_decimal) const
std::string to_string (void) const
display get_display (void) const
void right_shift (void)
bool operator== (const number &rhs) const
bool operator!= (const number &rhs) const
bool operator< (const number &rhs) const
bool operator<= (const number &rhs) const
bool operator> (const number &rhs) const
bool operator>= (const number &rhs) const
int sign (void) const
number fabs (void) const
void insert_digit_before_dot (int n)
void insert_digit_after_dot (int n)
void insert_dot (void)
bool has_overflowed (void) const

Static Public Member Functions

static number infinity (void)

Private Member Functions

void clear (void)
bool is_zero (void) const
void print_me (const char *file, int line) const
 number (const number_z &value, unsigned decimal, bool negative=false)

Static Private Member Functions

static unsigned max (unsigned a, unsigned b)
static int max (int a, int b)
static number positive_minus_positive (const number &lhs, const number &rhs)
static number positive_plus_positive (const number &lhs, const number &rhs)
static void truncate_floating_operation (number_z &t3, unsigned &t3ndec)
static void strip_redundant_decimal_places (number_z &t3, unsigned &t3ndec)

Private Attributes

number_z value
unsigned decimal
bool negative

Detailed Description

The number class is used to represent the values used by the calculator to perform arithmetic. It is limited to 16 digits, and a decimal point placed somewhere in those 16 digits. The minus sign is separate. The overflow bit indicates carry into the nonexistent next digit.

Definition at line 35 of file number.h.


Constructor & Destructor Documentation

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

Definition at line 21 of file number.cc.

The default constructor. Value is zero.

Definition at line 21 of file constructor_default.cc.

number::number ( const number rhs)

The copy constructor.

Parameters:
rhsThe right hand side of the initialization.

Definition at line 21 of file constructor_copy.cc.

number::number ( long  rhs)

A constructor.

Parameters:
rhsThe right hand side of the initialization.

Definition at line 21 of file constructor_long.cc.

number::number ( const number_z value,
unsigned  decimal,
bool  negative = false 
) [private]

A constructor.

Parameters:
valueThe underlying integer value.
decimalThe number of decimal places.
negativeWhether or not the number is negative.

Definition at line 21 of file constructor3.cc.


Member Function Documentation

void number::clear ( void  ) [private]

The clear method is used to reset the number back to zero.

Definition at line 22 of file clear.cc.

number number::fabs ( void  ) const

The fabs method may be used to obtain the the sign-less value of the number. That is, (n < 0 ? -n : n).

Definition at line 22 of file fabs.cc.

display number::get_display ( void  ) const

The get_display method may be used to obtain a representation of this number in a form suitable for displaying on the calculator front panel.

Definition at line 24 of file get_display.cc.

bool number::has_overflowed ( void  ) const

The has_overflowed method may be used to determine whether or not this numeric value is too large to fit on the 1614P's display.

Definition at line 22 of file has_overflowed.cc.

number number::infinity ( void  ) [static]

The infinity class member may be used to create a value that has overflowed, for use when division by zero occurs (and probably some other cases I haven't found yet).

Definition at line 22 of file infinity.cc.

The insert_digit_after_dot method is used when building a number, to insert a digit to the right of the decimal point.

Definition at line 40 of file insert.cc.

The insert_digit_before_dot method is used when building a number, to insert a digit to the left of the decimal point.

Definition at line 31 of file insert.cc.

void number::insert_dot ( void  )

The insert_dot method is used to process a redundant not when constructing a number.

Definition at line 24 of file insert.cc.

bool number::is_zero ( void  ) const [private]

The is_zero method is used to determine whether or not this number is exactly zero.

Definition at line 22 of file is_zero.cc.

static unsigned number::max ( unsigned  a,
unsigned  b 
) [inline, static, private]

Definition at line 330 of file number.h.

static int number::max ( int  a,
int  b 
) [inline, static, private]

Definition at line 332 of file number.h.

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

The inequality operator may be used to compare number values.

Parameters:
rhsThe right hand side of the comparison.

Definition at line 22 of file ne.cc.

number number::operator* ( const number rhs) const

The miltiplication operator may be used to multiply two numbers together.

Parameters:
rhsThe right hand side of the multiplication.

Definition at line 31 of file multiplication.cc.

void number::operator*= ( const number rhs)

The multiply-in-situ operator may be used to multiply this number by another number.

Parameters:
rhsThe right hand side of the multiplication.

Definition at line 24 of file multiplication.cc.

number number::operator+ ( const number rhs) const

The addition operator may be used to add two numbers together.

Parameters:
rhsThe right hand side of the addition.

Definition at line 31 of file addition.cc.

void number::operator+= ( const number rhs)

The add-in-situ operator may be used to add another number to this number.

Parameters:
rhsThe right hand side of the addition.

Definition at line 24 of file addition.cc.

number number::operator- ( const number rhs) const

The subtraction operator may be used to add subtract one number from another.

Parameters:
rhsThe right hand side of the subtraction.

Definition at line 31 of file subtraction.cc.

number number::operator- ( void  ) const

The negative operator may be used to invert the sign of a number.

Definition at line 22 of file negative.cc.

void number::operator-= ( const number rhs)

The subtract-in-situ operator may be used to subtract another number from this number.

Parameters:
rhsThe right hand side of the subtraction.

Definition at line 24 of file subtraction.cc.

number number::operator/ ( const number rhs) const

The division operator may be used to divide on number by aother.

Parameters:
rhsThe right hand side of the division.

Definition at line 32 of file division.cc.

void number::operator/= ( const number rhs)

The divide-in-situ operator may be used to divide this number by another number.

Parameters:
rhsThe right hand side of the division.

Definition at line 25 of file division.cc.

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

The less-than operator may be used to compare number values.

Parameters:
rhsThe right hand side of the comparison.

Definition at line 22 of file lt.cc.

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

The less-than_or-equal operator may be used to compare number values.

Parameters:
rhsThe right hand side of the comparison.

Definition at line 22 of file le.cc.

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

The assignment operator.

Parameters:
rhsThe right hand side of the assignment.

Definition at line 22 of file assignment.cc.

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

The equality operator may be used to compare number values.

Parameters:
rhsThe right hand side of the comparison.

Definition at line 22 of file eq.cc.

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

The larger-than operator may be used to compare number values.

Parameters:
rhsThe right hand side of the comparison.

Definition at line 22 of file gt.cc.

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

The larger-than_or-equal operator may be used to compare number values.

Parameters:
rhsThe right hand side of the comparison.

Definition at line 22 of file ge.cc.

number number::positive_minus_positive ( const number lhs,
const number rhs 
) [static, private]

The positive_minus_positive class method is used to subtract two positive numbers. This is a helper function for the operator+ and operator- methods.

Definition at line 24 of file positive_minus_positive.cc.

number number::positive_plus_positive ( const number lhs,
const number rhs 
) [static, private]

The positive_plus_positive class method is used to add two positive numbers. This is a helper function for the operator+ and operator- methods.

Definition at line 24 of file positive_plus_positive.cc.

void number::print_me ( const char *  file,
int  line 
) const [private]

The print_me method is used to print a representation of the number on stderr. This is for use when debugging.

Parameters:
fileThe source file, use the __FILE__ macro.
lineThe source line, use the __LINE__ macro.

Definition at line 24 of file print_me.cc.

void number::right_shift ( void  )

The right_shift method may be used to shift all of the digits of thenumber one place to the right, discarding the right most digit. If there are any decimal places, they are reduced by one. This is done in situ.

Definition at line 24 of file right-shift.cc.

number number::round_down ( int  preferred_decimal) const

The round_down method is used to round this value towards zero, to the given number of decimal places.

Parameters:
preferred_decimalThe desired number of decimal places, provided that the number will still fit.

Definition at line 100 of file round.cc.

number number::round_off ( int  preferred_decimal) const

The round_off method is used to round this value towards the nearest, to the given number of decimal places.

Parameters:
preferred_decimalThe desired number of decimal places, provided that the number will still fit.

Definition at line 68 of file round.cc.

number number::round_up ( int  preferred_decimal) const

The round_up method is used to round this value away from zero, to the given number of decimal places.

Parameters:
preferred_decimalThe desired number of decimal places, provided that the number will still fit.

Definition at line 25 of file round.cc.

int number::sign ( void  ) const

The sign method may be used to obtain the sign of the numkber.

Returns:
-1 if the number is negative, or 1 if the number is zero or one.

Definition at line 22 of file sign.cc.

number number::sqrt ( void  ) const

The sqrt method may be used to calculate the square root of a number. The sign is ignored.

Definition at line 24 of file sqrt.cc.

void number::strip_redundant_decimal_places ( number_z t3,
unsigned &  t3ndec 
) [static, private]

The strip_redundant_decimal_places class method is used to remove zero digits on the right, if they are to the right of the decimal point.

Definition at line 22 of file strip_redundant_decimals.cc.

long number::to_long ( void  ) const

The to_long method is used to extract the integer part of the number into a C long value. If the value would overflow, LONG_MAX or -LONG_MAX will be returned.

Definition at line 22 of file to_long.cc.

std::string number::to_string ( void  ) const

The to_string method may be used to form a textual representation of this number.

Definition at line 22 of file to_string.cc.

void number::truncate_floating_operation ( number_z t3,
unsigned &  t3ndec 
) [static, private]

The truncate_floating_operation class method is used to adjust the number of decimal places of an answer, so that it will fit on the 1614P's display.

Definition at line 36 of file truncate_floating_operation.cc.


Member Data Documentation

unsigned number::decimal [private]

The decimal instance variable is used to remember the number fo decimal places to give the value, if it were to be converted to floating point.

Definition at line 322 of file number.h.

bool number::negative [private]

The negative instance variable is used to remember whether or not the value is negative.

Definition at line 328 of file number.h.

The value instance variable is used to remember the value of the 16 digits. You could use an unsigned long long instead, but we want to produce some of the 1614P's niche behaviour.

Definition at line 315 of file number.h.


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