mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
Fix Integer approximation for 0.
Change-Id: Ib4bab6f4f776342bf6311d1e6f8b6d245d9a048a
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user