numData.h
1 //numData.h
2 //-------------------------------------------------------------------------------------------
3 /*
4  * Fco. Javier Bohórquez Ogalla
5  * 75766599-E
6  * Puerto Real (Cádiz)
7  * powersgame@gmail.com
8  */
9 //-------------------------------------------------------------------------------------------
10 /*
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24  * MA 02110-1301, USA.
25  */
26 //-------------------------------------------------------------------------------------------
27 #ifndef _NUMDATA_
28 #define _NUMDATA_
29 
30 #include <boost/multiprecision/cpp_dec_float.hpp>
31 #include <boost/multiprecision/cpp_int.hpp>
32 #include <math.h>
33 
34 using namespace boost::multiprecision;
35 using namespace std;
36 //-------------------------------------------------------------------------------------------
37 
38 //-------------------------------------------------------------------------------------------
39 class numData {
40  public:
41  numData ();
42  numData (const numData& n);
43  numData (char* str);
44  numData (double n);
45  numData (float n);
46  numData (int n);
47  numData (long unsigned int n);
48  numData (long int n);
49  numData (unsigned int n);
50  numData (std::basic_istream<char>::pos_type n);
51 
52  operator int();
53  operator double();
54  operator float();
55  operator bool();
56  operator long int();
57  operator long unsigned int();
58  operator unsigned int();
59 
60  inline numData operator+(numData lhs){ return lhs.num_ + this->num_; }
61  inline numData operator-(numData lhs){ return this->num_ - lhs.num_; }
62  inline numData operator-(){ return -this->num_; }
63  inline numData operator*(numData lhs){ return lhs.num_ * this->num_; }
64  inline numData operator/(numData lhs){ return this->num_ / lhs.num_; }
65  inline numData operator%(numData lhs){
66  int a = lhs.num_, b = this->num_;
67  return b % a;
68  }
69  inline numData& operator+=(const numData& rhs){
70  this->num_ += rhs.num_;
71  return *this;
72  }
73  inline numData& operator-=(const numData& rhs){
74  this->num_ -= rhs.num_;
75  return *this;
76  }
77  inline numData& operator/=(const numData& rhs){
78  this->num_ /= rhs.num_;
79  return *this;
80  }
81  inline numData& operator*=(const numData& rhs){
82  this->num_ *= rhs.num_;
83  return *this;
84  }
85  inline numData& operator%=(const numData& rhs){
86  this->num_ *= rhs.num_;
87  return *this;
88  }
89  inline double getNum () const { return num_; }
90  inline double& getNum () { return num_; }
91  private:
92  double num_;
93 };
94 //----------------------------------------------------------------------
95 
96 //----------------------------------------------------------------------
97 //~ typedef number<cpp_dec_float<100> > numData;
98 //~ typedef int128_t numInt;
99 
100 ostream& operator<<(ostream& os, const numData& obj);
101 istream& operator>>(istream& is, numData& obj);
102 
103  bool operator==(const numData& lhs, const numData& rhs);
104  bool operator==(const int& lhs, const numData& rhs);
105  bool operator==(const numData& lhs, const int& rhs);
106  bool operator==(const double& lhs, const numData& rhs);
107  bool operator==(const numData& lhs, const double& rhs);
108 //~ bool operator==(const numData& lhs, std::basic_istream<char>::pos_type& rhs);
109 
110  bool operator!=(const numData& lhs, const numData& rhs);
111  bool operator!=(const int& lhs, const numData& rhs);
112  bool operator!=(const numData& lhs, const int& rhs);
113  bool operator!=(const double& lhs, const numData& rhs);
114  bool operator!=(const numData& lhs, const double& rhs);
115 
116  bool operator< (const numData& lhs, const numData& rhs);
117  bool operator< (const int& lhs, const numData& rhs);
118  bool operator< (const numData& lhs, const int& rhs);
119  bool operator< (const double& lhs, const numData& rhs);
120  bool operator< (const numData& lhs, const double& rhs);
121 
122  bool operator> (const numData& lhs, const numData& rhs);
123  bool operator> (const int& lhs, const numData& rhs);
124  bool operator> (const numData& lhs, const int& rhs);
125  bool operator> (const double& lhs, const numData& rhs);
126  bool operator> (const numData& lhs, const double& rhs);
127 
128  bool operator<=(const numData& lhs, const numData& rhs);
129  bool operator<=(const int& lhs, const numData& rhs);
130  bool operator<=(const numData& lhs, const int& rhs);
131  bool operator<=(const double& lhs, const numData& rhs);
132  bool operator<=(const numData& lhs, const double& rhs);
133 
134  bool operator>=(const numData& lhs, const numData& rhs);
135  bool operator>=(const int& lhs, const numData& rhs);
136  bool operator>=(const numData& lhs, const int& rhs);
137  bool operator>=(const double& lhs, const numData& rhs);
138  bool operator>=(const numData& lhs, const double& rhs);
139 
140 numData pow (numData a, numData b ) ;
141 //----------------------------------------------------------------------
142 
143 //----------------------------------------------------------------------
144 typedef NUMTYPE num;
145 typedef REFCTYPE refC;
146 //----------------------------------------------------------------------
147 
148 //----------------------------------------------------------------------
149 #endif
150 //----------------------------------------------------------------------
151 
152 //Fco. javier Bóhorquez Ogalla