summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/main.cpp1
-rw-r--r--src/number.cpp33
-rw-r--r--src/packedintarray.cpp7
-rw-r--r--src/packedintarray.h1
4 files changed, 27 insertions, 15 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 0e5a77d..1499285 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -281,6 +281,7 @@ void fractest()
281 Number a( 8 ), b( 8 ); 281 Number a( 8 ), b( 8 );
282 282
283 a = "123.456"; 283 a = "123.456";
284 println("%1").arg( a );
284 b = "0.987"; 285 b = "0.987";
285 println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b ); 286 println("%1 + %2 = %3").arg( a ).arg( b ).arg( a + b );
286} 287}
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 )
diff --git a/src/packedintarray.cpp b/src/packedintarray.cpp
index 0e137bf..badc829 100644
--- a/src/packedintarray.cpp
+++ b/src/packedintarray.cpp
@@ -31,12 +31,13 @@ PackedIntArray::PackedIntArray( PackedIntArray::Unit iBitWidth ) :
31PackedIntArray::PackedIntArray( PackedIntArray::Unit iBitWidth, int iCount ): 31PackedIntArray::PackedIntArray( PackedIntArray::Unit iBitWidth, int iCount ):
32 iBitWidth( iBitWidth ), 32 iBitWidth( iBitWidth ),
33 aData( NULL ), 33 aData( NULL ),
34 iCapacity( StoreCount(iCount) ), 34 iCapacity( bitsizeof(StoreCount(iCount))/iBitWidth ),
35 iCount( iCount ), 35 iCount( iCount ),
36 uMask( 0 ) 36 uMask( 0 )
37{ 37{
38 aData = new Store[StoreCount(iCapacity)]; 38 int iSize = StoreCount(iCapacity);
39 memset( aData, 0, StoreCount(iCapacity)); 39 aData = new Store[iSize];
40 memset( aData, 0, iSize*sizeof(Store));
40 for( int j = 0; j < iBitWidth; j++ ) 41 for( int j = 0; j < iBitWidth; j++ )
41 uMask |= (1<<j); 42 uMask |= (1<<j);
42} 43}
diff --git a/src/packedintarray.h b/src/packedintarray.h
index de26a6a..ec109e5 100644
--- a/src/packedintarray.h
+++ b/src/packedintarray.h
@@ -22,6 +22,7 @@ public:
22 void set( const PackedIntArray &rSrc, int iStart, int iSize ); 22 void set( const PackedIntArray &rSrc, int iStart, int iSize );
23 void set( const PackedIntArray &rSrc ); 23 void set( const PackedIntArray &rSrc );
24 void trim(); 24 void trim();
25 int getBitWidth() const { return iBitWidth; }
25 26
26 Bu::String toBitString() const; 27 Bu::String toBitString() const;
27 Bu::String toString() const; 28 Bu::String toString() const;