diff --git a/poincare/include/poincare/integer.h b/poincare/include/poincare/integer.h index ec3391ca4..a93d714d9 100644 --- a/poincare/include/poincare/integer.h +++ b/poincare/include/poincare/integer.h @@ -5,6 +5,7 @@ #include typedef uint32_t native_uint_t; +typedef uint64_t double_native_uint_t; class Integer : public Expression { public: @@ -16,6 +17,7 @@ class Integer : public Expression { virtual bool identicalTo(Expression * e); //Integer add(Integer * i); const Integer operator+(const Integer &other) const; + const Integer operator*(const Integer &other) const; bool operator==(const Integer &other) const; protected: virtual void layout(); diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index 373035cbe..bc67a81a4 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -69,6 +69,31 @@ const Integer Integer::operator+(const Integer &other) const { return Integer(bits, sumSize); } +const Integer Integer::operator*(const Integer &other) const { + uint16_t productSize = other.m_numberOfBits + m_numberOfBits; + uint16_t intArraySize = arraySize(productSize); + native_uint_t * bits = (native_uint_t *)malloc(intArraySize*sizeof(native_uint_t)); + memset(bits, 0, intArraySize*sizeof(native_uint_t)); + + uint16_t myArraySize = arraySize(m_numberOfBits); + uint16_t otherArraySize = arraySize(other.m_numberOfBits); + + native_uint_t carry = 0; + for (uint16_t i=0; i>32; //FIXME: 32 is hardcoded here! + } + m_bits[i+otherArraySize] = carry; + } + + return Integer(bits, productSize); +} + /* char * Integer::bits() { if (m_numberOfBits > INTEGER_IMMEDIATE_LIMIT) {