00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef __NUM__
00052 #define __NUM__
00053
00054
00055
00056
00057
00058 class num
00059 {
00060 int fType;
00061 union {
00062 int i;
00063 float f;
00064 } fData;
00065
00066 public:
00067
00068 num (int x=0) : fType(0) { fData.i = x; }
00069 num (double x) : fType(1) { fData.f = (float)x; }
00070 num (float x) : fType(1) { fData.f = x; }
00071 num (const num& n) : fType(n.fType) { fData.i = n.fData.i; }
00072
00073 num& operator = (int n) { fType = 0; fData.i = n; return *this; }
00074 num& operator = (float n) { fType = 1; fData.f = n; return *this; }
00075
00076
00077 bool operator == (const num& n) const { return fType == n.fType && fData.i == n.fData.i; }
00078 bool operator != (const num& n) const { return fType != n.fType || fData.i != n.fData.i; }
00079
00080
00081 int type() const { return fType; }
00082 operator int() const { return (fType) ? int(fData.f) : fData.i; }
00083 operator float() const { return (fType) ? fData.f : float(fData.i); }
00084
00085 };
00086
00087
00088 inline int isfloat (const num& n) { return n.type(); }
00089
00090 inline const num operator+ (const num& x, const num& y)
00091 { return (isfloat(x)|isfloat(y)) ? num(float(x)+float(y)) : num(int(x)+int(y)); }
00092
00093 inline const num operator- (const num& x, const num& y)
00094 { return (isfloat(x)|isfloat(y)) ? num(float(x)-float(y)) : num(int(x)-int(y)); }
00095
00096 inline const num operator* (const num& x, const num& y)
00097 { return (isfloat(x)|isfloat(y)) ? num(float(x)*float(y)) : num(int(x)*int(y)); }
00098
00099 inline const num operator/ (const num& x, const num& y)
00100 { return (isfloat(x)|isfloat(y)) ? num(float(x)/float(y)) : num(int(x)/int(y)); }
00101
00102 inline const num operator% (const num& x, const num& y)
00103 { return num(int(x)%int(y)); }
00104
00105
00106
00107 inline const num operator<< (const num& x, const num& y)
00108 { return num(int(x)<<int(y)); }
00109
00110 inline const num operator>> (const num& x, const num& y)
00111 { return num(int(x)>>int(y)); }
00112
00113
00114
00115 inline const num operator& (const num& x, const num& y)
00116 { return num(int(x)&int(y)); }
00117
00118 inline const num operator| (const num& x, const num& y)
00119 { return num(int(x)|int(y)); }
00120
00121 inline const num operator^ (const num& x, const num& y)
00122 { return num(int(x)^int(y)); }
00123
00124
00125
00126 inline const num operator> (const num& x, const num& y)
00127 { return (isfloat(x)|isfloat(y)) ? num(float(x)>float(y)) : num(int(x)>int(y)); }
00128
00129 inline const num operator< (const num& x, const num& y)
00130 { return (isfloat(x)|isfloat(y)) ? num(float(x)<float(y)) : num(int(x)<int(y)); }
00131
00132 inline const num operator>= (const num& x, const num& y)
00133 { return (isfloat(x)|isfloat(y)) ? num(float(x)>=float(y)) : num(int(x)>=int(y)); }
00134
00135 inline const num operator<= (const num& x, const num& y)
00136 { return (isfloat(x)|isfloat(y)) ? num(float(x)<=float(y)) : num(int(x)<=int(y)); }
00137
00138 inline const num operator== (const num& x, const num& y)
00139 { return (isfloat(x)|isfloat(y)) ? num(float(x)==float(y)) : num(int(x)==int(y)); }
00140
00141 inline const num operator!= (const num& x, const num& y)
00142 { return (isfloat(x)|isfloat(y)) ? num(float(x)!=float(y)) : num(int(x)!=int(y)); }
00143
00144
00145 #endif