summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2013-04-21 21:51:17 -0600
committerMike Buland <mike@xagasoft.com>2013-04-21 21:51:17 -0600
commita520fc5740da7d50a289357e4e6e529b826454e7 (patch)
treeb54cbe7d8e33e262e87697425f08b77446f75aa5
parent7b87784eaf497a976b56be4fd169fb52c9bf7dea (diff)
downloadclic-a520fc5740da7d50a289357e4e6e529b826454e7.tar.gz
clic-a520fc5740da7d50a289357e4e6e529b826454e7.tar.bz2
clic-a520fc5740da7d50a289357e4e6e529b826454e7.tar.xz
clic-a520fc5740da7d50a289357e4e6e529b826454e7.zip
FIxed fractional support in comparisons.
They still don't handle mixed scale comparisons correctly, it shouldn't be too hard to add, but yeah...not supported yet.
-rw-r--r--src/main.cpp60
-rw-r--r--src/number.cpp46
2 files changed, 102 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 5e420f5..d1b9d1c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -194,6 +194,66 @@ void numbertestcomp()
194 compcheck( -123, <=, -122 ); 194 compcheck( -123, <=, -122 );
195 compcheck( -122, <=, -123 ); 195 compcheck( -122, <=, -123 );
196 compcheck( 123, <=, -122 ); 196 compcheck( 123, <=, -122 );
197
198 println("-==-==- Non-Integer Test -==-==-");
199
200 a.setScale( 8 );
201 b.setScale( 8 );
202 println("-==- Greater Than -==-");
203 compcheck( 10.1, >, 10.4 );
204 compcheck( 10.1, >, 10.1 );
205 compcheck( 10.4, >, 10.1 );
206 compcheck( 10.413, >, 10.413 );
207 compcheck( 10.41329135, >, 10.41329134 );
208 compcheck( 10.41329134, >, 10.41329135 );
209 compcheck( 10.41329135, >, 10.41329135 );
210 compcheck( -123.3, >, 123.2 );
211 compcheck( -123.3, >, -123.2 );
212 compcheck( -123.3, >, -123.3 );
213 compcheck( -123.3, >, -123.2 );
214 compcheck( 123.3, >, -123.2 );
215
216 println("-==- Less Than -==-");
217 compcheck( 10.1, <, 10.4 );
218 compcheck( 10.1, <, 10.1 );
219 compcheck( 10.4, <, 10.1 );
220 compcheck( 10.413, <, 10.413 );
221 compcheck( 10.41329135, <, 10.41329134 );
222 compcheck( 10.41329134, <, 10.41329135 );
223 compcheck( 10.41329135, <, 10.41329135 );
224 compcheck( -123.3, <, 123.2 );
225 compcheck( -123.3, <, -123.2 );
226 compcheck( -123.3, <, -123.3 );
227 compcheck( -123.3, <, -123.2 );
228 compcheck( 123.3, <, -123.2 );
229
230 println("-==- Greater Than or Equal To -==-");
231 compcheck( 10.1, >=, 10.4 );
232 compcheck( 10.1, >=, 10.1 );
233 compcheck( 10.4, >=, 10.1 );
234 compcheck( 10.413, >=, 10.413 );
235 compcheck( 10.41329135, >=, 10.41329134 );
236 compcheck( 10.41329134, >=, 10.41329135 );
237 compcheck( 10.41329135, >=, 10.41329135 );
238 compcheck( -123.3, >=, 123.2 );
239 compcheck( -123.3, >=, -123.2 );
240 compcheck( -123.3, >=, -123.3 );
241 compcheck( -123.3, >=, -123.2 );
242 compcheck( 123.3, >=, -123.2 );
243
244 println("-==- Less Than or Equal To -==-");
245 compcheck( 10.1, <=, 10.4 );
246 compcheck( 10.1, <=, 10.1 );
247 compcheck( 10.4, <=, 10.1 );
248 compcheck( 10.413, <=, 10.413 );
249 compcheck( 10.41329135, <=, 10.41329134 );
250 compcheck( 10.41329134, <=, 10.41329135 );
251 compcheck( 10.41329135, <=, 10.41329135 );
252 compcheck( -123.3, <=, 123.2 );
253 compcheck( -123.3, <=, -123.2 );
254 compcheck( -123.3, <=, -123.3 );
255 compcheck( -123.3, <=, -123.2 );
256 compcheck( 123.3, <=, -123.2 );
197} 257}
198 258
199int getHob( int x ) 259int getHob( int x )
diff --git a/src/number.cpp b/src/number.cpp
index d16bd98..b7a420c 100644
--- a/src/number.cpp
+++ b/src/number.cpp
@@ -133,6 +133,11 @@ bool Number::operator==( const Number &rhs ) const
133 if( aInt[j] != rhs.aInt[j] ) 133 if( aInt[j] != rhs.aInt[j] )
134 return false; 134 return false;
135 } 135 }
136 for( int j = 0; j < aFrac.getSize(); j++ )
137 {
138 if( aFrac[j] != rhs.aFrac[j] )
139 return false;
140 }
136 141
137 return true; 142 return true;
138} 143}
@@ -164,6 +169,14 @@ bool Number::operator>( const Number &rhs ) const
164 else if( iDiff > 0 ) 169 else if( iDiff > 0 )
165 return bPositive; 170 return bPositive;
166 } 171 }
172 for( int j = 0; j < iScale; j++ )
173 {
174 int iDiff = aFrac[j] - rhs.aFrac[j];
175 if( iDiff < 0 )
176 return !bPositive;
177 else if( iDiff > 0 )
178 return bPositive;
179 }
167 return false; 180 return false;
168} 181}
169 182
@@ -189,6 +202,14 @@ bool Number::operator<( const Number &rhs ) const
189 else if( iDiff < 0 ) 202 else if( iDiff < 0 )
190 return bPositive; 203 return bPositive;
191 } 204 }
205 for( int j = 0; j < iScale; j++ )
206 {
207 int iDiff = aFrac[j] - rhs.aFrac[j];
208 if( iDiff > 0 )
209 return !bPositive;
210 else if( iDiff < 0 )
211 return bPositive;
212 }
192 return false; 213 return false;
193} 214}
194 215
@@ -214,6 +235,14 @@ bool Number::operator>=( const Number &rhs ) const
214 else if( iDiff > 0 ) 235 else if( iDiff > 0 )
215 return bPositive; 236 return bPositive;
216 } 237 }
238 for( int j = 0; j < iScale; j++ )
239 {
240 int iDiff = aFrac[j] - rhs.aFrac[j];
241 if( iDiff < 0 )
242 return !bPositive;
243 else if( iDiff > 0 )
244 return bPositive;
245 }
217 return true; 246 return true;
218} 247}
219 248
@@ -239,6 +268,14 @@ bool Number::operator<=( const Number &rhs ) const
239 else if( iDiff < 0 ) 268 else if( iDiff < 0 )
240 return bPositive; 269 return bPositive;
241 } 270 }
271 for( int j = 0; j < iScale; j++ )
272 {
273 int iDiff = aFrac[j] - rhs.aFrac[j];
274 if( iDiff > 0 )
275 return !bPositive;
276 else if( iDiff < 0 )
277 return bPositive;
278 }
242 return true; 279 return true;
243} 280}
244 281
@@ -518,14 +555,15 @@ void Number::setScale( int iNewScale )
518 return; 555 return;
519 else if( iScale < iNewScale ) 556 else if( iScale < iNewScale )
520 { 557 {
521 for(; iScale < iNewScale; iNewScale-- ) 558 while( aFrac.getSize() < iNewScale )
522 aFrac.remove(); 559 aFrac.append(0);
523 } 560 }
524 else 561 else
525 { 562 {
526 for(; iScale > iNewScale; iNewScale++ ) 563 while( aFrac.getSize() > iNewScale )
527 aFrac.append(0); 564 aFrac.remove();
528 } 565 }
566 iScale = iNewScale;
529} 567}
530 568
531Number Number::add( const Number &rhs, bool bSub ) const 569Number Number::add( const Number &rhs, bool bSub ) const