From 01bb2607cbd50b944f6abd89b31514ee535490cd Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 17 Apr 2013 15:55:34 -0600 Subject: Well, the fractional portion is...making...progress... --- src/number.cpp | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file 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 void Number::set( const Bu::String &sNum ) { + Bu::println("Parsing: '%1'").arg( sNum ); aInt.clear(); bPositive = true; - int j = sNum.getSize()-1; + int iPt; + for( iPt = 0; iPt < sNum.getSize() && sNum[iPt] != '.'; iPt++ ) { } - if( sNum[j] == '+' ) - j--; - else if( sNum[j] == '-' ) + int iEnd = 0; + if( sNum[iEnd] == '+' ) + iEnd++; + else if( sNum[iEnd] == '-' ) { bPositive = false; - j--; + iEnd++; } - for( ; sNum[j] == '0' && j >= 0; j-- ) { } - - for( ; j >= 0; j-- ) + for( ; iEnd < sNum.getSize() && sNum[iEnd] == '0'; iEnd++ ) { } + + for( int j = iPt-1; j >= iEnd; j-- ) { Bu::println(" -> '%1'").arg( sNum[j] ); if( sNum[j] == '.' ) @@ -262,6 +265,21 @@ void Number::set( const Bu::String &sNum ) aInt.append( sNum[j]-'a'+10 ); } + if( iScale > 0 ) + { + int iFrac = 0; + for( int j = iPt+1; j < sNum.getSize(); j++ ) + { + Bu::println(" => '%1'").arg( sNum[j] ); + if( sNum[j] >= '0' && sNum[j] <= '9' ) + aFrac.set( iFrac++, sNum[j]-'0' ); + else + aFrac.set( iFrac++, sNum[j]-'a'+10 ); + if( iFrac >= iScale ) + break; + } + } + Bu::println("done."); } @@ -287,6 +305,18 @@ Bu::String Number::toString() const else sRet += x+'0'; } + if( iScale > 0 ) + { + sRet += '.'; + for( int j = 0; j < iScale; j++ ) + { + int x = aFrac.get( j ); + if( x >= 10 ) + sRet += x-10+'a'; + else + sRet += x+'0'; + } + } return sRet; } -- cgit v1.2.3