summaryrefslogtreecommitdiff
path: root/src/number.cpp
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 /src/number.cpp
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.
Diffstat (limited to '')
-rw-r--r--src/number.cpp46
1 files changed, 42 insertions, 4 deletions
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