[poincare] In Integer::approximate, exclude special case 0 first to

avoid breaking assertions

Change-Id: I7dea2e05a485a581251b43be1814f00615f17594
This commit is contained in:
Émilie Feral
2017-11-30 17:39:04 +01:00
parent b5cd6c76ca
commit 95ce07dfc7

View File

@@ -473,6 +473,15 @@ IntegerDivision Integer::udiv(const Integer & numerator, const Integer & denomin
template<typename T>
T Integer::approximate() const {
if (isZero()) {
/* 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.
*/
T result = m_negative ? -0.0 : 0.0;
return result;
}
union {
uint64_t uint_result;
T float_result;
@@ -544,16 +553,6 @@ T Integer::approximate() const {
// shift the mantissa if the rounding increase the length in bits of the
// mantissa.
if (isZero()) {
/* 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.
*/
T result = m_negative ? -0.0 : 0.0;
return result;
}
u.uint_result = 0;
u.uint_result |= ((uint64_t)sign << (totalNumberOfBits-1));
u.uint_result |= ((uint64_t)exponent << mantissaNbBit);