diff options
Diffstat (limited to '')
-rw-r--r-- | src/number.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/number.cpp b/src/number.cpp index b045e7c..5ef8009 100644 --- a/src/number.cpp +++ b/src/number.cpp | |||
@@ -5,17 +5,17 @@ | |||
5 | 5 | ||
6 | #define RadixToBits( x ) ((int)(log((x))*0xb.8aa3b295c17fp-3+1.0)) | 6 | #define RadixToBits( x ) ((int)(log((x))*0xb.8aa3b295c17fp-3+1.0)) |
7 | 7 | ||
8 | Number::Number( int iRadix, int iOrd ) : | 8 | Number::Number( int iRadix, int iScale ) : |
9 | iRadix( iRadix ), | 9 | iRadix( iRadix ), |
10 | iOrd( iOrd ), | 10 | iScale( iScale ), |
11 | bPositive( true ), | 11 | bPositive( true ), |
12 | aInt( RadixToBits(iRadix) ) | 12 | aInt( RadixToBits(iRadix) ) |
13 | { | 13 | { |
14 | } | 14 | } |
15 | 15 | ||
16 | Number::Number( const Bu::String &sData, int iRadix, int iOrd ) : | 16 | Number::Number( const Bu::String &sData, int iRadix, int iScale ) : |
17 | iRadix( iRadix ), | 17 | iRadix( iRadix ), |
18 | iOrd( iOrd ), | 18 | iScale( iScale ), |
19 | bPositive( true ), | 19 | bPositive( true ), |
20 | aInt( RadixToBits( iRadix ) ) | 20 | aInt( RadixToBits( iRadix ) ) |
21 | { | 21 | { |
@@ -50,7 +50,7 @@ Number Number::operator-( const Number &rhs ) const | |||
50 | 50 | ||
51 | Number Number::operator*( const Number &rhs ) const | 51 | Number Number::operator*( const Number &rhs ) const |
52 | { | 52 | { |
53 | Number ret( iRadix, iOrd ); | 53 | Number ret( iRadix, iScale ); |
54 | 54 | ||
55 | int iCnt = aInt.getSize()+rhs.aInt.getSize(); | 55 | int iCnt = aInt.getSize()+rhs.aInt.getSize(); |
56 | 56 | ||
@@ -94,14 +94,14 @@ Number Number::operator*( const Number &rhs ) const | |||
94 | 94 | ||
95 | Number Number::operator/( const Number &rhs ) const | 95 | Number Number::operator/( const Number &rhs ) const |
96 | { | 96 | { |
97 | Number q( iRadix, iOrd ), r( iRadix, iOrd ); | 97 | Number q( iRadix, iScale ), r( iRadix, iScale ); |
98 | divide( rhs, q, r ); | 98 | divide( rhs, q, r ); |
99 | return q; | 99 | return q; |
100 | } | 100 | } |
101 | 101 | ||
102 | Number Number::operator%( const Number &rhs ) const | 102 | Number Number::operator%( const Number &rhs ) const |
103 | { | 103 | { |
104 | Number q( iRadix, iOrd ), r( iRadix, iOrd ); | 104 | Number q( iRadix, iScale ), r( iRadix, iScale ); |
105 | divide( rhs, q, r ); | 105 | divide( rhs, q, r ); |
106 | return r; | 106 | return r; |
107 | } | 107 | } |
@@ -116,7 +116,7 @@ Number Number::operator-() const | |||
116 | bool Number::operator==( const Number &rhs ) const | 116 | bool Number::operator==( const Number &rhs ) const |
117 | { | 117 | { |
118 | if( rhs.bPositive != bPositive || | 118 | if( rhs.bPositive != bPositive || |
119 | rhs.iOrd != iOrd || | 119 | rhs.iScale != iScale || |
120 | rhs.aInt.getSize() != aInt.getSize() ) | 120 | rhs.aInt.getSize() != aInt.getSize() ) |
121 | return false; | 121 | return false; |
122 | 122 | ||
@@ -258,7 +258,7 @@ void Number::set( const Number &sNum ) | |||
258 | { | 258 | { |
259 | aInt.set( sNum.aInt ); | 259 | aInt.set( sNum.aInt ); |
260 | bPositive = sNum.bPositive; | 260 | bPositive = sNum.bPositive; |
261 | iOrd = sNum.iOrd; | 261 | iScale = sNum.iScale; |
262 | } | 262 | } |
263 | 263 | ||
264 | Bu::String Number::toString() const | 264 | Bu::String Number::toString() const |
@@ -280,16 +280,16 @@ Bu::String Number::toString() const | |||
280 | return sRet; | 280 | return sRet; |
281 | } | 281 | } |
282 | 282 | ||
283 | int Number::digit( int iOrder ) const | 283 | int Number::digit( int iIdx ) const |
284 | { | 284 | { |
285 | if( iOrder >= aInt.getSize() ) | 285 | if( iIdx >= aInt.getSize() ) |
286 | return 0; | 286 | return 0; |
287 | return aInt[iOrder]; | 287 | return aInt[iIdx]; |
288 | } | 288 | } |
289 | 289 | ||
290 | Number Number::add( const Number &rhs, bool bSub ) const | 290 | Number Number::add( const Number &rhs, bool bSub ) const |
291 | { | 291 | { |
292 | Number ret( iRadix, iOrd ); | 292 | Number ret( iRadix, iScale ); |
293 | 293 | ||
294 | int iPlaces = Bu::buMax(rhs.aInt.getSize(), aInt.getSize() ); | 294 | int iPlaces = Bu::buMax(rhs.aInt.getSize(), aInt.getSize() ); |
295 | 295 | ||
@@ -386,7 +386,7 @@ void Number::divide( const Number &rhs, Number &q, Number &r ) const | |||
386 | do | 386 | do |
387 | { | 387 | { |
388 | // Bu::println("%1\n-----").arg( r.aInt.toString() ); | 388 | // Bu::println("%1\n-----").arg( r.aInt.toString() ); |
389 | Number sub( iRadix, iOrd ); | 389 | Number sub( iRadix, iScale ); |
390 | for(;;) | 390 | for(;;) |
391 | { | 391 | { |
392 | // Bu::println(" -> Anchor: %1, Sample: %2").arg( iAnchor ).arg( iSample ); | 392 | // Bu::println(" -> Anchor: %1, Sample: %2").arg( iAnchor ).arg( iSample ); |
@@ -406,7 +406,7 @@ void Number::divide( const Number &rhs, Number &q, Number &r ) const | |||
406 | break; | 406 | break; |
407 | } | 407 | } |
408 | 408 | ||
409 | Number x( iRadix, iOrd ); | 409 | Number x( iRadix, iScale ); |
410 | int iRes = 0; | 410 | int iRes = 0; |
411 | for( ; x <= sub; iRes++, x = x + rhs ) { } | 411 | for( ; x <= sub; iRes++, x = x + rhs ) { } |
412 | x = sub - (x - rhs); | 412 | x = sub - (x - rhs); |