Calculator  Step 6
Classes | Functions
number.hpp File Reference
#include <memory>
#include <ostream>
#include <string>
#include "rational.hpp"

Go to the source code of this file.

Classes

class  number
 

Functions

bool operator== (number a, number b)
 
bool operator!= (number a, number b)
 
bool operator< (number a, number b)
 
bool operator<= (number a, number b)
 
bool operator> (number a, number b)
 
bool operator>= (number a, number b)
 
number operator- (number n)
 
std::ostream & operator<< (std::ostream &stream, number n)
 

Function Documentation

bool operator!= ( number  a,
number  b 
)
inline

Compare two number objects for numeric inequality. The objects are coerced to a common type before comparing.

Parameters
aThe left-hand operand
bThe right-hand operand
Returns
true if a != b (watch out for floating-point comparisons).

Definition at line 149 of file number.hpp.

150 {
151  return not (a == b);
152 }
number operator- ( number  n)
inline

Negate a number.

Parameters
nthe number
Returns
-n

Definition at line 202 of file number.hpp.

203 {
204  return number{0} - n;
205 }
bool operator< ( number  a,
number  b 
)
inline

Compare two number objects for numeric less-than. The objects are coerced to a common type before comparing.

Parameters
aThe left-hand operand
bThe right-hand operand
Returns
true if a < b (watch out for floating-point comparisons).

Definition at line 160 of file number.hpp.

References number::less().

161 {
162  return a.less(b);
163 }
bool less(number b)
Definition: number.cpp:70
std::ostream& operator<< ( std::ostream &  stream,
number  n 
)
inline

Print a number

Parameters
streamThe output stream
nThe number to print

Definition at line 211 of file number.hpp.

References number::print().

212 {
213  n.print(stream);
214  return stream;
215 }
void print(std::ostream &stream)
Definition: number.cpp:51
bool operator<= ( number  a,
number  b 
)
inline

Compare two number objects for numeric less-than-or-equal. The objects are coerced to a common type before comparing.

Parameters
aThe left-hand operand
bThe right-hand operand
Returns
true if a <= b (watch out for floating-point comparisons).

Definition at line 171 of file number.hpp.

172 {
173  return not(b < a);
174 }
bool operator== ( number  a,
number  b 
)
inline

Compare two number objects for numeric equality. The objects are coerced to a common type before comparing.

Parameters
aThe left-hand operand
bThe right-hand operand
Returns
true if a == b (watch out for floating-point comparisons).

Definition at line 138 of file number.hpp.

References number::equals().

139 {
140  return a.equals(b);
141 }
bool equals(number b)
Definition: number.cpp:64
bool operator> ( number  a,
number  b 
)
inline

Compare two number objects for numeric greater-than. The objects are coerced to a common type before comparing.

Parameters
aThe left-hand operand
bThe right-hand operand
Returns
true if a > b (watch out for floating-point comparisons).

Definition at line 182 of file number.hpp.

183 {
184  return b < a;
185 }
bool operator>= ( number  a,
number  b 
)
inline

Compare two number objects for numeric greater-than-or-equal. The objects are coerced to a common type before comparing.

Parameters
aThe left-hand operand
bThe right-hand operand
Returns
true if a >= b (watch out for floating-point comparisons).

Definition at line 193 of file number.hpp.

194 {
195  return not (a < b);
196 }