00001 #ifndef STARLAB_XREAL_H
00002 # define STARLAB_XREAL_H
00003
00005
00007
00008
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #define TWO64 (18446744073709551616.0)
00038 #define TWO63 ( 9223372036854775808.0)
00039 #define TWO64I (5.42101086242752217e-20)
00040 #define TWO63M ( 9223372036854775807)
00041 #define TWO63N (-9223372036854775808)
00042
00043 typedef long long xint_t;
00044 typedef unsigned long long xfrac_t;
00045
00046 class xreal {
00047
00048 private:
00049 xint_t i;
00050 xfrac_t f;
00051
00052 public:
00053
00054
00055
00056 xreal();
00057
00058 xreal(xint_t ii, xfrac_t ff);
00059 xreal(int ii);
00060 xreal(real x);
00061
00062
00063
00064 xint_t get_i() {return i;}
00065 xfrac_t get_f() {return f;}
00066 real get_frac() {return TWO64I*f;}
00067
00068
00069
00070 int to_int() {return i;}
00071 real to_real();
00072
00073 void print(ostream& s = cerr,
00074 bool newline = false);
00075
00076 xreal::operator int() {return to_int();}
00077 xreal::operator real() {return to_real();}
00078
00079
00080
00081 xreal operator - ();
00082 xreal operator + (const xreal y);
00083 xreal operator - (const xreal y);
00084 xreal& operator += (const xreal y);
00085 xreal& operator -= (const xreal y);
00086 xreal operator + (const real y);
00087 xreal operator - (const real y);
00088 xreal& operator += (const real y);
00089 xreal& operator -= (const real y);
00090
00091
00092
00093
00094 bool operator == (const xreal y);
00095 bool operator != (const xreal y);
00096 bool operator < (const xreal y);
00097 bool operator <= (const xreal y);
00098 bool operator > (const xreal y);
00099 bool operator >= (const xreal y);
00100
00101 friend istream & operator >> (ostream & , xreal &);
00102 };
00103
00104 inline ostream & operator << (ostream & s, xreal x)
00105 {
00106 return s << (real)x;
00107
00108 }
00109
00110 istream & operator >> (istream & s, xreal & x);
00111
00112
00113
00114 inline bool operator == (xreal x, real y) {return (x == (xreal)y);}
00115 inline bool operator == (real x, xreal y) {return ((xreal)x == y);}
00116 inline bool operator != (xreal x, real y) {return (x != (xreal)y);}
00117 inline bool operator != (real x, xreal y) {return ((xreal)x != y);}
00118 inline bool operator < (xreal x, real y) {return (x < (xreal)y);}
00119 inline bool operator < (real x, xreal y) {return ((xreal)x < y);}
00120 inline bool operator > (xreal x, real y) {return (x > (xreal)y);}
00121 inline bool operator > (real x, xreal y) {return ((xreal)x > y);}
00122 inline bool operator <= (xreal x, real y) {return (x <= (xreal)y);}
00123 inline bool operator <= (real x, xreal y) {return ((xreal)x <= y);}
00124 inline bool operator >= (xreal x, real y) {return (x >= (xreal)y);}
00125 inline bool operator >= (real x, xreal y) {return ((xreal)x >= y);}
00126
00127
00128
00129
00130
00131
00132 void put_real_number(ostream & s, char * label, xreal x);
00133
00134 #endif