diff options
author | Mike Buland <mike@xagasoft.com> | 2013-04-17 15:55:34 -0600 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2013-04-17 15:55:34 -0600 |
commit | 01bb2607cbd50b944f6abd89b31514ee535490cd (patch) | |
tree | 164b1fede8cc6fba9e604d600b93cf44ba69bf9a /src/number.cpp | |
parent | 439c5a36138a66b0c76ec3136c79a86ca3619f17 (diff) | |
download | clic-01bb2607cbd50b944f6abd89b31514ee535490cd.tar.gz clic-01bb2607cbd50b944f6abd89b31514ee535490cd.tar.bz2 clic-01bb2607cbd50b944f6abd89b31514ee535490cd.tar.xz clic-01bb2607cbd50b944f6abd89b31514ee535490cd.zip |
Well, the fractional portion is...making...progress...
Diffstat (limited to '')
-rw-r--r-- | src/number.cpp | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/number.cpp b/src/number.cpp index c7a4cc6..8ebe870 100644 --- a/src/number.cpp +++ b/src/number.cpp | |||
@@ -238,20 +238,23 @@ bool Number::operator<=( const Number &rhs ) const | |||
238 | 238 | ||
239 | void Number::set( const Bu::String &sNum ) | 239 | void Number::set( const Bu::String &sNum ) |
240 | { | 240 | { |
241 | Bu::println("Parsing: '%1'").arg( sNum ); | ||
241 | aInt.clear(); | 242 | aInt.clear(); |
242 | bPositive = true; | 243 | bPositive = true; |
243 | int j = sNum.getSize()-1; | 244 | int iPt; |
245 | for( iPt = 0; iPt < sNum.getSize() && sNum[iPt] != '.'; iPt++ ) { } | ||
244 | 246 | ||
245 | if( sNum[j] == '+' ) | 247 | int iEnd = 0; |
246 | j--; | 248 | if( sNum[iEnd] == '+' ) |
247 | else if( sNum[j] == '-' ) | 249 | iEnd++; |
250 | else if( sNum[iEnd] == '-' ) | ||
248 | { | 251 | { |
249 | bPositive = false; | 252 | bPositive = false; |
250 | j--; | 253 | iEnd++; |
251 | } | 254 | } |
252 | for( ; sNum[j] == '0' && j >= 0; j-- ) { } | 255 | for( ; iEnd < sNum.getSize() && sNum[iEnd] == '0'; iEnd++ ) { } |
253 | 256 | ||
254 | for( ; j >= 0; j-- ) | 257 | for( int j = iPt-1; j >= iEnd; j-- ) |
255 | { | 258 | { |
256 | Bu::println(" -> '%1'").arg( sNum[j] ); | 259 | Bu::println(" -> '%1'").arg( sNum[j] ); |
257 | if( sNum[j] == '.' ) | 260 | if( sNum[j] == '.' ) |
@@ -262,6 +265,21 @@ void Number::set( const Bu::String &sNum ) | |||
262 | aInt.append( sNum[j]-'a'+10 ); | 265 | aInt.append( sNum[j]-'a'+10 ); |
263 | } | 266 | } |
264 | 267 | ||
268 | if( iScale > 0 ) | ||
269 | { | ||
270 | int iFrac = 0; | ||
271 | for( int j = iPt+1; j < sNum.getSize(); j++ ) | ||
272 | { | ||
273 | Bu::println(" => '%1'").arg( sNum[j] ); | ||
274 | if( sNum[j] >= '0' && sNum[j] <= '9' ) | ||
275 | aFrac.set( iFrac++, sNum[j]-'0' ); | ||
276 | else | ||
277 | aFrac.set( iFrac++, sNum[j]-'a'+10 ); | ||
278 | if( iFrac >= iScale ) | ||
279 | break; | ||
280 | } | ||
281 | } | ||
282 | |||
265 | Bu::println("done."); | 283 | Bu::println("done."); |
266 | } | 284 | } |
267 | 285 | ||
@@ -287,6 +305,18 @@ Bu::String Number::toString() const | |||
287 | else | 305 | else |
288 | sRet += x+'0'; | 306 | sRet += x+'0'; |
289 | } | 307 | } |
308 | if( iScale > 0 ) | ||
309 | { | ||
310 | sRet += '.'; | ||
311 | for( int j = 0; j < iScale; j++ ) | ||
312 | { | ||
313 | int x = aFrac.get( j ); | ||
314 | if( x >= 10 ) | ||
315 | sRet += x-10+'a'; | ||
316 | else | ||
317 | sRet += x+'0'; | ||
318 | } | ||
319 | } | ||
290 | 320 | ||
291 | return sRet; | 321 | return sRet; |
292 | } | 322 | } |