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 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/number.cpp') 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 ); -- cgit v1.2.3