- Main Page
- Classes
- Files

# number.hpp

Go to the documentation of this file.

    00001 #ifndef NUMBER_HPP_
    00002 #define NUMBER_HPP_
    00003
    00004 #include <ostream>
    00005 #include <string>
    00006
    00007 #include "rational.hpp"
    00008
    00010 class number_impl;
    00011
    00015 class number
    00016 {
    00017 public:
    00022   number();
    00029   number(int x);
    00034   number(long x);
    00040   number(double x);
    00044   number(rational<long> const& x);
    00049   number(number const& n);
    00054   number& operator=(number const& n);
    00056   number(std::istream& stream);
    00059   ~number();
    00060
    00064   void save(std::ostream& stream)  const;
    00065
    00071   bool equals(number b);
    00072
    00078   bool less(number b);
    00079
    00086   void coerce(number& rhs);
    00087
    00090   std::string to_string() const;
    00091
    00095   void print(std::ostream& stream);
    00096
    00102   number operator+(number rhs);
    00108   number operator-(number rhs);
    00114   number operator*(number rhs);
    00121   number operator/(number rhs);
    00122
    00123 private:
    00127   number(number_impl* ptr);
    00128
    00129   number_impl* pimpl_;
    00130 };
    00131
    00138 inline bool operator==(number a, number b)
    00139 {
    00140   return a.equals(b);
    00141 }
    00142
    00149 inline bool operator!=(number a, number b)
    00150 {
    00151   return not (a == b);
    00152 }
    00153
    00160 inline bool operator<(number a, number b)
    00161 {
    00162   return a.less(b);
    00163 }
    00164
    00171 inline bool operator<=(number a, number b)
    00172 {
    00173   return not(b < a);
    00174 }
    00175
    00182 inline bool operator>(number a, number b)
    00183 {
    00184   return b < a;
    00185 }
    00186
    00193 inline bool operator>=(number a, number b)
    00194 {
    00195   return not (a < b);
    00196 }
    00197
    00202 inline number operator-(number n)
    00203 {
    00204   return number(0) - n;
    00205 }
    00206
    00211 inline std::ostream& operator<<(std::ostream& stream, number n)
    00212 {
    00213   n.print(stream);
    00214   return stream;
    00215 }
    00216
    00217 #endif