Browse Source

Handle real::DEFAULT_BIGIT_COUNT changes a bit better.

Most operators do not yet handle reals of different sizes, but
this change fixes the most glaring bugs.
legacy
Sam Hocevar 7 years ago
parent
commit
c7c34312fe
1 changed files with 11 additions and 2 deletions
  1. +11
    -2
      src/math/real.cpp

+ 11
- 2
src/math/real.cpp View File

@@ -41,7 +41,15 @@ static real load_pi();
#define LOL_CONSTANT_GETTER(name, value) \
template<> real const& real::name() \
{ \
static real const ret = value; \
static real ret; \
static int prev_bigit_count = -1; \
/* If the default bigit count has changed, we must recompute
* the value with the desired precision. */ \
if (prev_bigit_count != DEFAULT_BIGIT_COUNT) \
{ \
ret = value; \
prev_bigit_count = DEFAULT_BIGIT_COUNT; \
} \
return ret; \
}

@@ -121,7 +129,8 @@ template<> real::Real(double d)
m_exponent = exponent - ((1 << 10) - 1);
m_mantissa.resize(DEFAULT_BIGIT_COUNT);
m_mantissa[0] = (bigit_t)(u.x >> 20);
m_mantissa[1] = (bigit_t)(u.x << 12);
if (m_mantissa.count() > 1)
m_mantissa[1] = (bigit_t)(u.x << 12);
break;
}
}


Loading…
Cancel
Save