From c7c34312feefcdfbf8a588e41176d45470095888 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 26 Aug 2017 14:49:33 +0200 Subject: [PATCH] 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. --- src/math/real.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/math/real.cpp b/src/math/real.cpp index df146517..729379a1 100644 --- a/src/math/real.cpp +++ b/src/math/real.cpp @@ -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; } }