diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index db849dd32..22cad5a60 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #define MAX(a,b) ((a)>(b)?a:b) #define NATIVE_UINT_BIT_COUNT (8*sizeof(native_uint_t)) @@ -21,7 +20,6 @@ uint8_t log2(native_uint_t v) { } bool Integer::operator==(const Integer &other) const { - printf("Comparing %d and %d\n", other.m_numberOfDigits, m_numberOfDigits); if (other.m_numberOfDigits != m_numberOfDigits) { return false; } @@ -36,7 +34,6 @@ bool Integer::operator==(const Integer &other) const { Integer::Integer(native_uint_t i) { m_numberOfDigits = 1; m_digits = (native_uint_t *)malloc(sizeof(native_uint_t)); - printf("%d has %d\n", i, m_numberOfDigits); *m_digits = i; } @@ -62,8 +59,8 @@ const Integer Integer::operator+(const Integer &other) const { const Integer Integer::operator*(const Integer &other) const { uint16_t productSize = other.m_numberOfDigits + m_numberOfDigits; - native_uint_t * bits = (native_uint_t *)malloc(productSize*sizeof(native_uint_t)); - memset(bits, 0, productSize*sizeof(native_uint_t)); + native_uint_t * digits = (native_uint_t *)malloc(productSize*sizeof(native_uint_t)); + memset(digits, 0, productSize*sizeof(native_uint_t)); native_uint_t carry = 0; for (uint16_t i=0; i>32; //FIXME: 32 is hardcoded here! } - m_digits[i+other.m_numberOfDigits] = carry; + digits[i+other.m_numberOfDigits] += carry; } - return Integer(bits, productSize); + while (digits[productSize-1] == 0) { + productSize--; + /* At this point we may realloc m_digits to a smaller size. */ + } + + return Integer(digits, productSize); } /* diff --git a/poincare/test/integer.cpp b/poincare/test/integer.cpp index a663c36c1..37c86f8e9 100644 --- a/poincare/test/integer.cpp +++ b/poincare/test/integer.cpp @@ -13,7 +13,7 @@ QUIZ_CASE(poincare_integer_add) { } QUIZ_CASE(poincare_integer_multiply) { - //assert(Integer(12) * Integer(34) == Integer(408)); + assert(Integer(12) * Integer(34) == Integer(408)); } QUIZ_CASE(poincare_integer_parse_integer) {