summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2013-04-22 13:04:25 -0600
committerMike Buland <mike@xagasoft.com>2013-04-22 13:04:25 -0600
commitd7ccd9c4d8e5a5bb4f12b36b3e4ad3105c5a9317 (patch)
treea7b6753b6a049be68a91749aaae8da23979ed83a /src
parenta520fc5740da7d50a289357e4e6e529b826454e7 (diff)
downloadclic-d7ccd9c4d8e5a5bb4f12b36b3e4ad3105c5a9317.tar.gz
clic-d7ccd9c4d8e5a5bb4f12b36b3e4ad3105c5a9317.tar.bz2
clic-d7ccd9c4d8e5a5bb4f12b36b3e4ad3105c5a9317.tar.xz
clic-d7ccd9c4d8e5a5bb4f12b36b3e4ad3105c5a9317.zip
Fixed bug in multiply, added toInt32 function.
Multiply was ignoring the zero column, which was odd. I fixed this other places but apparently missed multiply.
Diffstat (limited to 'src')
-rw-r--r--src/number.cpp14
-rw-r--r--src/number.h2
2 files changed, 15 insertions, 1 deletions
diff --git a/src/number.cpp b/src/number.cpp
index b7a420c..d95ab90 100644
--- a/src/number.cpp
+++ b/src/number.cpp
@@ -63,7 +63,7 @@ Number Number::operator*( const Number &rhs ) const
63// Bu::println("Pos %1").arg(j); 63// Bu::println("Pos %1").arg(j);
64 int iPos = iCarry; 64 int iPos = iCarry;
65 iCarry = 0; 65 iCarry = 0;
66 for( int k = 1-rhs.iScale; k < rhs.aInt.getSize(); k++ ) 66 for( int k = -rhs.iScale; k < rhs.aInt.getSize(); k++ )
67 { 67 {
68// if( j-k < 0 ) 68// if( j-k < 0 )
69// break; 69// break;
@@ -566,6 +566,18 @@ void Number::setScale( int iNewScale )
566 iScale = iNewScale; 566 iScale = iNewScale;
567} 567}
568 568
569int32_t Number::toInt32() const
570{
571 int32_t ret = 0;
572 int32_t ord = 1;
573 for( int j = 0; j < aInt.getSize(); j++ )
574 {
575 ret += ord * aInt.get( j );
576 ord *= iRadix;
577 }
578 return ret;
579}
580
569Number Number::add( const Number &rhs, bool bSub ) const 581Number Number::add( const Number &rhs, bool bSub ) const
570{ 582{
571 Number ret( Bu::buMax(iScale,rhs.iScale), iRadix ); 583 Number ret( Bu::buMax(iScale,rhs.iScale), iRadix );
diff --git a/src/number.h b/src/number.h
index 8c9cd28..0816a17 100644
--- a/src/number.h
+++ b/src/number.h
@@ -46,6 +46,8 @@ public:
46 int getScale() const { return iScale; } 46 int getScale() const { return iScale; }
47 void setScale( int iNewScale ); 47 void setScale( int iNewScale );
48 48
49 int32_t toInt32() const;
50
49private: 51private:
50 Number add( const Number &rhs, bool bSub ) const; 52 Number add( const Number &rhs, bool bSub ) const;
51 53