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 #ifndef TYPE
00047 #error "TYPE is not defined !"
00048 #endif
00049
00050 #ifndef NUMBER
00051 #error "NUMBER is not defined !"
00052 #endif
00053
00054
00055 friend BOOL isEqualTo( const NUMBER& l, const NUMBER& r ) {
00056 int temp = MathStateEqualTo[ (int)l.state ][ (int)r.state ];
00057 if ( temp < 2 ) return (BOOL)temp;
00058 return ( l.value == r.value );
00059 }
00060
00061 friend BOOL isLessThan( const NUMBER& l, const NUMBER& r ) {
00062 int temp = MathStateLessThan[ (int)l.state ][ (int)r.state ];
00063 if ( temp < 2 ) return (BOOL)temp;
00064 return (l.value < r.value);
00065 }
00066
00067 friend BOOL isBiggerThan( const NUMBER& l, const NUMBER& r ) {
00068 int temp = MathStateBiggerThan[ (int)l.state ][ (int)r.state ];
00069 if ( temp < 2 ) return (BOOL)temp;
00070 return (l.value > r.value);
00071 }
00072
00073 inline friend BOOL operator==( const NUMBER& l, const NUMBER& r ) {
00074 return isEqualTo( l, r );
00075 }
00076
00077 inline friend BOOL operator!=( const NUMBER& l, const NUMBER& r ) {
00078 return !isEqualTo( l, r );
00079 }
00080
00081 inline friend BOOL operator<( const NUMBER& l, const NUMBER& r ) {
00082 return isLessThan( l, r );
00083 }
00084
00085 inline friend BOOL operator<=( const NUMBER& l, const NUMBER& r ) {
00086 return ( isLessThan( l, r ) || isEqualTo( l, r ) );
00087 }
00088
00089 inline friend BOOL operator>( const NUMBER& l, const NUMBER& r ) {
00090 return isBiggerThan( l, r );
00091 }
00092
00093 inline friend BOOL operator>=( const NUMBER& l, const NUMBER& r ) {
00094 return ( isBiggerThan( l, r ) || isEqualTo( l, r ) );
00095 }
00096
00097
00098 friend NUMBER add( const NUMBER& l, const NUMBER& r ) {
00099 MathState s = MathStateAdd[ (int)l.state ][ (int)r.state ];
00100 return NUMBER( l.value + r.value, s );
00101 }
00102
00103 friend NUMBER sub( const NUMBER& l, const NUMBER& r ) {
00104 MathState s = MathStateSub[ (int)l.state ][ (int)r.state ];
00105 return NUMBER( l.value - r.value, s );
00106 }
00107
00108 friend NUMBER mult( const NUMBER& l, const NUMBER& r ) {
00109 MathState s = MathStateMult[ (int)l.state ][ (int)r.state ];
00110 return NUMBER( l.value * r.value, s );
00111 }
00112
00113 friend NUMBER div( const NUMBER& l, const NUMBER& r ) {
00114 MathState s = MathStateDiv[ (int)l.state ][ (int)r.state ];
00115 if ( s != Valid ) return NUMBER( l.value, s );
00116 return NUMBER( l.value / r.value, s );
00117 }
00118
00119 inline friend NUMBER operator+( const NUMBER& l, const NUMBER& r ) {
00120 return add( l, r );
00121 }
00122
00123 inline friend NUMBER operator-( const NUMBER& l, const NUMBER& r ) {
00124 return sub( l, r );
00125 }
00126
00127 inline friend NUMBER operator*( const NUMBER& l, const NUMBER& r ) {
00128 return mult( l, r );
00129 }
00130
00131 inline friend NUMBER operator/( const NUMBER& l, const NUMBER& r ) {
00132 return div( l, r );
00133 }
00134
00135
00136 inline const NUMBER& operator=(const NUMBER& N ) {
00137 value = N.value;
00138 state = N.state;
00139 return *this;
00140 }
00141
00142 inline NUMBER operator!() {
00143 return NUMBER( (TYPE)!value, state );
00144 }
00145
00146 inline NUMBER operator-() {
00147 if ( (int)state < 4 ) return NUMBER( (TYPE)( -1 * value ), Valid );
00148 return NUMBER( (TYPE)( -1 * value ), state );
00149 }
00150
00151
00152 inline NUMBER operator--() {
00153 --value;
00154 return *this;
00155 }
00156
00157 inline NUMBER operator--( int ) {
00158 value--;
00159 return *this;
00160 }
00161
00162 inline NUMBER operator++() {
00163 ++value;
00164 return *this;
00165 }
00166
00167 inline NUMBER operator++( int ) {
00168 value++;
00169 return *this;
00170 }