From d7ccd9c4d8e5a5bb4f12b36b3e4ad3105c5a9317 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 22 Apr 2013 13:04:25 -0600 Subject: 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. --- src/number.cpp | 14 +++++++++++++- src/number.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 // Bu::println("Pos %1").arg(j); int iPos = iCarry; iCarry = 0; - for( int k = 1-rhs.iScale; k < rhs.aInt.getSize(); k++ ) + for( int k = -rhs.iScale; k < rhs.aInt.getSize(); k++ ) { // if( j-k < 0 ) // break; @@ -566,6 +566,18 @@ void Number::setScale( int iNewScale ) iScale = iNewScale; } +int32_t Number::toInt32() const +{ + int32_t ret = 0; + int32_t ord = 1; + for( int j = 0; j < aInt.getSize(); j++ ) + { + ret += ord * aInt.get( j ); + ord *= iRadix; + } + return ret; +} + Number Number::add( const Number &rhs, bool bSub ) const { 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: int getScale() const { return iScale; } void setScale( int iNewScale ); + int32_t toInt32() const; + private: Number add( const Number &rhs, bool bSub ) const; -- cgit v1.2.3