Calculator
Step 6
|
#include <number.hpp>
Public Member Functions | |
number () | |
number (int x) | |
number (long x) | |
number (long long x) | |
number (double x) | |
number (rational< long long > const &x) | |
number (number const &)=default | |
number (number &&)=default | |
number & | operator= (number const &)=default |
number & | operator= (number &&)=default |
~number ()=default | |
number (std::istream &stream) | |
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 (std::shared_ptr< number_impl > ptr) | |
Private Attributes | |
std::shared_ptr< number_impl > | pimpl_ |
Number class represents a numeric value. Numbers of different types are supported, as well as conversions between types.
Definition at line 16 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/().
number::number | ( | int | x | ) |
Construct an int
value. For the sake of simplicitly, all integers are stored as long
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.
number::number | ( | long | x | ) |
Construct a long
value. For the sake of simplicitly, all integers are stored as long
long
values.
x | The value of the number |
Definition at line 15 of file number.cpp.
number::number | ( | long long | x | ) |
Construct a long
long
value. For the sake of simplicitly, all integers are stored as long
long
values.
x | The value of the number |
Definition at line 19 of file number.cpp.
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 27 of file number.cpp.
number::number | ( | rational< long long > const & | x | ) |
Construct a rational number.
x | The value of the number |
Definition at line 23 of file number.cpp.
|
default |
|
default |
|
default |
number::number | ( | std::istream & | stream | ) |
Construct a number by reading from a library file.
Definition at line 31 of file number.cpp.
References number_impl::read_library().
|
private |
Private constructor to create a number from a number_impl.
ptr | Pointer to a number_impl. |
Definition at line 35 of file number.cpp.
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 56 of file number.cpp.
References number(), and pimpl_.
Referenced by equals(), less(), operator*(), operator+(), operator-(), and operator/().
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 64 of file number.cpp.
References coerce(), 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 70 of file number.cpp.
References coerce(), and pimpl_.
Referenced by operator<().
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 88 of file number.cpp.
References coerce(), number(), and pimpl_.
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 76 of file number.cpp.
References 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 82 of file number.cpp.
References coerce(), 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 94 of file number.cpp.
References coerce(), number(), and pimpl_.
void number::print | ( | std::ostream & | stream | ) |
Print a number to a stream.
stream | The output stream |
Definition at line 51 of file number.cpp.
References pimpl_.
Referenced by operator<<().
void number::save | ( | std::ostream & | stream | ) | const |
Save a number to a library file.
stream | the library stream |
Definition at line 39 of file number.cpp.
References pimpl_.
Referenced by BOOST_AUTO_TEST_CASE(), and node_number::save_node().
std::string number::to_string | ( | ) | const |
Convert this number to a human-readable string.
Definition at line 45 of file number.cpp.
References pimpl_.
Referenced by BOOST_AUTO_TEST_CASE().
|
private |
Definition at line 129 of file number.hpp.
Referenced by coerce(), equals(), less(), operator*(), operator+(), operator-(), operator/(), print(), save(), and to_string().