diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index 575fb1357..b712e4f2d 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -308,6 +308,15 @@ float Integer::approximate(Context& context) const { mantissa |= (beforeLastDigit >> numberOfBitsInLastDigit); } + if ((m_numberOfDigits==1) && (m_digits[0]==0)) { + /* This special case for 0 is needed, because the current algorithm assumes + * that the big integer is non zero, thus puts the exponent to 126 (integer + * area), the issue is that when the mantissa is 0, a "shadow bit" is + * assumed to be there, thus 126 0x000000 is equal to 0.5 and not zero. + */ + return m_negative ? -0.0f : 0.0f; + } + uint_result = 0; uint_result |= (sign << 31); uint_result |= (exponent << 23); diff --git a/poincare/test/integer.cpp b/poincare/test/integer.cpp index 64d9de213..ac704b0fa 100644 --- a/poincare/test/integer.cpp +++ b/poincare/test/integer.cpp @@ -54,4 +54,7 @@ QUIZ_CASE(poincare_integer_approximate) { Context context; assert(Integer(1).approximate(context) == 1.0f); assert(Integer("12345678").approximate(context) == 12345678.0f); + assert(Integer("0").approximate(context) == 0); + assert(Integer("-0").approximate(context) == -0); + assert(Integer(-1).approximate(context) == -1); }