summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/number.cpp30
-rw-r--r--src/number.h8
2 files changed, 19 insertions, 19 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
8Number::Number( int iRadix, int iOrd ) : 8Number::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
16Number::Number( const Bu::String &sData, int iRadix, int iOrd ) : 16Number::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
51Number Number::operator*( const Number &rhs ) const 51Number 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
95Number Number::operator/( const Number &rhs ) const 95Number 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
102Number Number::operator%( const Number &rhs ) const 102Number 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
116bool Number::operator==( const Number &rhs ) const 116bool 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
264Bu::String Number::toString() const 264Bu::String Number::toString() const
@@ -280,16 +280,16 @@ Bu::String Number::toString() const
280 return sRet; 280 return sRet;
281} 281}
282 282
283int Number::digit( int iOrder ) const 283int 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
290Number Number::add( const Number &rhs, bool bSub ) const 290Number 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);
diff --git a/src/number.h b/src/number.h
index cdae1df..deac5eb 100644
--- a/src/number.h
+++ b/src/number.h
@@ -7,8 +7,8 @@
7class Number 7class Number
8{ 8{
9public: 9public:
10 Number( int iRadix=10, int iOrd=0 ); 10 Number( int iRadix=10, int iScale=0 );
11 Number( const Bu::String &sData, int iRadix=10, int iOrd=0 ); 11 Number( const Bu::String &sData, int iRadix=10, int iScale=0 );
12 virtual ~Number(); 12 virtual ~Number();
13 13
14 Number &operator=( const Bu::String &sNum ); 14 Number &operator=( const Bu::String &sNum );
@@ -40,14 +40,14 @@ public:
40 40
41 Bu::String toString() const; 41 Bu::String toString() const;
42 42
43 int digit( int iOrder ) const; 43 int digit( int iIdx ) const;
44 44
45private: 45private:
46 Number add( const Number &rhs, bool bSub ) const; 46 Number add( const Number &rhs, bool bSub ) const;
47 47
48private: 48private:
49 int iRadix; 49 int iRadix;
50 int iOrd; 50 int iScale;
51 bool bPositive; 51 bool bPositive;
52 PackedIntArray aInt; 52 PackedIntArray aInt;
53}; 53};