diff options
Diffstat (limited to 'src/number.cpp')
-rw-r--r-- | src/number.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/number.cpp b/src/number.cpp index 9fd3865..2d45e7e 100644 --- a/src/number.cpp +++ b/src/number.cpp | |||
@@ -52,21 +52,21 @@ Number Number::operator-( const Number &rhs ) const | |||
52 | 52 | ||
53 | Number Number::operator*( const Number &rhs ) const | 53 | Number Number::operator*( const Number &rhs ) const |
54 | { | 54 | { |
55 | Number ret( iScale, iRadix ); | 55 | Number ret( iScale+rhs.iScale,iRadix ); |
56 | 56 | ||
57 | int iCnt = aInt.getSize()+rhs.aInt.getSize(); | 57 | int iCnt = aInt.getSize()+rhs.aInt.getSize(); |
58 | 58 | ||
59 | int iCarry = 0; | 59 | int iCarry = 0; |
60 | int iZeros = 0; | 60 | int iZeros = 0; |
61 | for( int j = 0; j < iCnt || iCarry > 0; j++ ) | 61 | for( int j = 1-iScale-rhs.iScale; j < iCnt || iCarry > 0; j++ ) |
62 | { | 62 | { |
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 = 0; k < rhs.aInt.getSize(); k++ ) | 66 | for( int k = 1-rhs.iScale; k < rhs.aInt.getSize(); k++ ) |
67 | { | 67 | { |
68 | if( j-k < 0 ) | 68 | // if( j-k < 0 ) |
69 | break; | 69 | // break; |
70 | 70 | ||
71 | int iRes = digit(j-k)*rhs.digit(k); | 71 | int iRes = digit(j-k)*rhs.digit(k); |
72 | iPos += iRes; | 72 | iPos += iRes; |
@@ -75,13 +75,19 @@ Number Number::operator*( const Number &rhs ) const | |||
75 | // arg( j-k ).arg( digit(j-k) ).arg( k ).arg( rhs.digit(k) ). | 75 | // arg( j-k ).arg( digit(j-k) ).arg( k ).arg( rhs.digit(k) ). |
76 | // arg( iRes ).arg( iPos ).arg( iCarry ); | 76 | // arg( iRes ).arg( iPos ).arg( iCarry ); |
77 | } | 77 | } |
78 | if( (iPos%iRadix) == 0 ) | 78 | // Bu::println("=> %1 = %2 (%3 / %4)").arg( j ).arg( iPos ).arg( iPos%iRadix ).arg( iPos/iRadix ); |
79 | iZeros++; | 79 | if( j < 0 ) |
80 | ret.aFrac.set( -1-j, (iPos%iRadix) ); | ||
80 | else | 81 | else |
81 | { | 82 | { |
82 | for(; iZeros > 0; iZeros-- ) | 83 | if( (iPos%iRadix) == 0 ) |
83 | ret.aInt.append( 0 ); | 84 | iZeros++; |
84 | ret.aInt.append( iPos%iRadix ); | 85 | else |
86 | { | ||
87 | for(; iZeros > 0; iZeros-- ) | ||
88 | ret.aInt.append( 0 ); | ||
89 | ret.aInt.append( iPos%iRadix ); | ||
90 | } | ||
85 | } | 91 | } |
86 | iCarry += iPos/iRadix; | 92 | iCarry += iPos/iRadix; |
87 | } | 93 | } |