summaryrefslogtreecommitdiff
path: root/src/number.cpp
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2013-04-17 20:36:32 -0600
committerMike Buland <mike@xagasoft.com>2013-04-17 20:36:32 -0600
commit10559f103a72a36eda3e9649ffb229b1b39743c0 (patch)
tree769153b7387eb065f9b6ae6c43114e6bc250af5e /src/number.cpp
parent01bb2607cbd50b944f6abd89b31514ee535490cd (diff)
downloadclic-10559f103a72a36eda3e9649ffb229b1b39743c0.tar.gz
clic-10559f103a72a36eda3e9649ffb229b1b39743c0.tar.bz2
clic-10559f103a72a36eda3e9649ffb229b1b39743c0.tar.xz
clic-10559f103a72a36eda3e9649ffb229b1b39743c0.zip
Fractional portions parse now.
Diffstat (limited to 'src/number.cpp')
-rw-r--r--src/number.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/number.cpp b/src/number.cpp
index 8ebe870..49e8a60 100644
--- a/src/number.cpp
+++ b/src/number.cpp
@@ -9,8 +9,8 @@ Number::Number( int iScale, int iRadix ) :
9 iRadix( iRadix ), 9 iRadix( iRadix ),
10 iScale( iScale ), 10 iScale( iScale ),
11 bPositive( true ), 11 bPositive( true ),
12 aInt( RadixToBits(iRadix) ), 12 aInt( RadixToBits( iRadix ) ),
13 aFrac( RadixToBits(iRadix), iScale ) 13 aFrac( aInt.getBitWidth(), iScale )
14{ 14{
15} 15}
16 16
@@ -19,7 +19,7 @@ Number::Number( const Bu::String &sData, int iScale, int iRadix ) :
19 iScale( iScale ), 19 iScale( iScale ),
20 bPositive( true ), 20 bPositive( true ),
21 aInt( RadixToBits( iRadix ) ), 21 aInt( RadixToBits( iRadix ) ),
22 aFrac( RadixToBits(iRadix), iScale ) 22 aFrac( aInt.getBitWidth(), iScale )
23{ 23{
24 set( sData ); 24 set( sData );
25} 25}
@@ -286,29 +286,38 @@ void Number::set( const Bu::String &sNum )
286void Number::set( const Number &sNum ) 286void Number::set( const Number &sNum )
287{ 287{
288 aInt.set( sNum.aInt ); 288 aInt.set( sNum.aInt );
289 aFrac.set( sNum.aFrac );
289 bPositive = sNum.bPositive; 290 bPositive = sNum.bPositive;
290 iScale = sNum.iScale; 291 iScale = sNum.iScale;
292 iRadix = sNum.iRadix;
291} 293}
292 294
293Bu::String Number::toString() const 295Bu::String Number::toString() const
294{ 296{
295 if( aInt.getSize() == 0 ) 297 int iSigDig = iScale-1;
298 for( ; iSigDig >= 0 && aFrac.get( iSigDig ) == 0; iSigDig-- ) { }
299 if( aInt.getSize() == 0 && iSigDig <= 0 )
296 return "0"; 300 return "0";
297 Bu::String sRet; 301 Bu::String sRet;
298 if( !bPositive ) 302 if( !bPositive )
299 sRet += '-'; 303 sRet += '-';
300 for( int j = aInt.getSize()-1; j >= 0; j-- ) 304 if( aInt.getSize() > 0 )
301 { 305 {
302 int x = aInt.get( j ); 306 for( int j = aInt.getSize()-1; j >= 0; j-- )
303 if( x >= 10 ) 307 {
304 sRet += x-10+'a'; 308 int x = aInt.get( j );
305 else 309 if( x >= 10 )
306 sRet += x+'0'; 310 sRet += x-10+'a';
311 else
312 sRet += x+'0';
313 }
307 } 314 }
308 if( iScale > 0 ) 315 else
316 sRet += "0";
317 if( iSigDig >= 0 )
309 { 318 {
310 sRet += '.'; 319 sRet += '.';
311 for( int j = 0; j < iScale; j++ ) 320 for( int j = 0; j <= iSigDig; j++ )
312 { 321 {
313 int x = aFrac.get( j ); 322 int x = aFrac.get( j );
314 if( x >= 10 ) 323 if( x >= 10 )