#include <number.hpp>
Public Member Functions | |
number () | |
number (int x) | |
number (long x) | |
number (double x) | |
number (rational< long > const &x) | |
number (number const &n) | |
number & | operator= (number const &n) |
number (std::istream &stream) | |
~number () | |
void | save (std::ostream &stream) const |
bool | equals (number b) |
bool | less (number b) |
void | coerce (number &rhs) |
std::string | to_string () const |
void | print (std::ostream &stream) |
number | operator+ (number rhs) |
number | operator- (number rhs) |
number | operator * (number rhs) |
number | operator/ (number rhs) |
Private Member Functions | |
number (number_impl *ptr) | |
Private Attributes | |
number_impl * | pimpl_ |
Definition at line 15 of file number.hpp.
number::number | ( | ) |
Construct a void value. The calculator does not currently use void, but I can't think of a better value for a default number constructor.
Definition at line 7 of file number.cpp.
Referenced by coerce(), operator *(), operator+(), operator-(), and operator/().
00008 : pimpl_(new number_void()) 00009 {}
number::number | ( | int | x | ) |
Construct an int
value. For the sake of simplicitly, all integers are stored as long
values. This overloaded operator exists so simple uses of, say, number(0), are not ambiguous.
x | The value of the number |
Definition at line 11 of file number.cpp.
00012 : pimpl_(new number_long(x)) 00013 {}
number::number | ( | long | x | ) |
Construct a long
value. For the sake of simplicitly, all integers are stored as long
values.
x | The value of the number |
Definition at line 15 of file number.cpp.
00016 : pimpl_(new number_long(x)) 00017 {}
number::number | ( | double | x | ) |
Construct a floating-point value. For the sake of simplicitly, all floating-point numbers are stored as double
values.
x | The value of the number |
Definition at line 23 of file number.cpp.
00024 : pimpl_(new number_double(x)) 00025 {}
number::number | ( | rational< long > const & | x | ) |
x | The value of the number |
Definition at line 19 of file number.cpp.
00020 : pimpl_(new number_rational(x)) 00021 {}
number::number | ( | number const & | n | ) |
Copy constructor. The actual number_impl is not copied; only the reference count is incremented.
n | The number to copy |
Definition at line 27 of file number.cpp.
References number_impl::add_ref(), and pimpl_.
number::number | ( | std::istream & | stream | ) |
Construct a number by reading from a library file.
Definition at line 33 of file number.cpp.
00034 : pimpl_(number_impl::read_library(stream)) 00035 {}
number::~number | ( | ) |
Destructor decrements the reference count.
Definition at line 41 of file number.cpp.
References number_impl::del_ref(), and pimpl_.
number::number | ( | number_impl * | ptr | ) | [private] |
Private constructor to create a number from a number_impl.
ptr | Pointer to a number_impl. |
Definition at line 37 of file number.cpp.
00038 : pimpl_(pimpl) 00039 {}
Copy assignment operator. The actual number_impl is not copied; only the reference count is incremented.
n | The number to copy |
Definition at line 46 of file number.cpp.
References number_impl::add_ref(), number_impl::del_ref(), and pimpl_.
00047 { 00048 that.pimpl_->add_ref(); 00049 this->pimpl_->del_ref(); 00050 this->pimpl_ = that.pimpl_; 00051 return *this; 00052 }
void number::save | ( | std::ostream & | stream | ) | const |
Save a number to a library file.
stream | the library stream |
Definition at line 54 of file number.cpp.
References pimpl_, and number_impl::save().
Referenced by BOOST_AUTO_TEST_CASE(), and node_number::save_node().
bool number::equals | ( | number | b | ) |
Test for equality. Coerce this
and b
to the same type, then compare.
b | the number to compare |
*this
is numerically equal to b
Definition at line 79 of file number.cpp.
References coerce(), number_impl::equals(), and pimpl_.
Referenced by operator==().
bool number::less | ( | number | b | ) |
Test for less-than. Coerce this
and b
to the same type, then compare.
b | the number to compare |
*this
is numerically less than b
Definition at line 85 of file number.cpp.
References coerce(), number_impl::less(), and pimpl_.
Referenced by operator<().
void number::coerce | ( | number & | rhs | ) |
Coerce this
and rhs
to the same arithmetic type. Promote the "smaller" number to the "larger" type.
[in,out] | rhs | the right-hand-side operand |
Definition at line 71 of file number.cpp.
References number(), pimpl_, and number_impl::promote().
Referenced by equals(), less(), operator *(), operator+(), operator-(), and operator/().
00072 { 00073 // Promote that number to the type of this. 00074 that = number(this->pimpl_->promote(*that.pimpl_)); 00075 // Promote this to the type of that. 00076 *this = number(that.pimpl_->promote(*this->pimpl_)); 00077 }
std::string number::to_string | ( | ) | const |
Convert this number to a human-readable string.
Definition at line 60 of file number.cpp.
References pimpl_, and number_impl::to_string().
Referenced by BOOST_AUTO_TEST_CASE().
void number::print | ( | std::ostream & | stream | ) |
Print a number to a stream.
stream | The output stream |
Definition at line 66 of file number.cpp.
References pimpl_, and number_impl::print().
Referenced by operator<<().
Addition operator. Coerce this
and rhs
to the same type, then add rhs
and this
.
rhs | The right-hand-side operand |
*this
+ rhs
Definition at line 91 of file number.cpp.
References number_impl::add(), coerce(), number(), and pimpl_.
Subtraction operator. Coerce this
and rhs
to the same type, then subtract rhs
from this
.
rhs | The right-hand-side operand |
*this
- rhs
Definition at line 97 of file number.cpp.
References coerce(), number(), pimpl_, and number_impl::subtract().
Multiplication operator. Coerce this
and rhs
to the same type, then multiply this
by rhs
.
rhs | The right-hand-side operand |
*this
* rhs
Definition at line 103 of file number.cpp.
References coerce(), number_impl::multiply(), number(), and pimpl_.
Division operator. Coerce this
and rhs
to the same type, then divide this
by rhs
.
rhs | The right-hand-side operand |
*this
/ rhs
calc_error | if rhs == 0. |
Definition at line 109 of file number.cpp.
References coerce(), number_impl::divide(), number(), and pimpl_.
number_impl* number::pimpl_ [private] |
Definition at line 129 of file number.hpp.
Referenced by coerce(), equals(), less(), number(), operator *(), operator+(), operator-(), operator/(), operator=(), print(), save(), to_string(), and ~number().