Ignore:
Timestamp:
Oct 12, 2011, 12:01:44 AM (12 years ago)
Author:
sam
Message:

core: fix an accuracy error in real::re() and real::sqrt() introduced in
the 16-to-32-bit refactoring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/real.cpp

    r1016 r1017  
    2323{
    2424
    25 static int const BIGIT_BITS = 32;
    26 
    2725real::real(float f) { *this = (double)f; }
    2826real::real(int i) { *this = (double)i; }
     
    501499    ret.m_signexp |= (exponent - 1) & 0x7fffffffu;
    502500
    503     /* FIXME: log2(BIGITS) steps of Newton-Raphson seems to be enough for
     501    /* FIXME: 1+log2(BIGITS) steps of Newton-Raphson seems to be enough for
    504502     * convergence, but this hasn't been checked seriously. */
    505     for (int i = 2; i < real::BIGITS; i *= 2)
     503    for (int i = 1; i <= real::BIGITS; i *= 2)
    506504        ret = ret * (real::R_2 - ret * x);
    507505
     
    545543    ret.m_signexp |= exponent & 0x7fffffffu;
    546544
    547     /* FIXME: log2(BIGITS) steps of Newton-Raphson seems to be enough for
     545    /* FIXME: 1+log2(BIGITS) steps of Newton-Raphson seems to be enough for
    548546     * convergence, but this hasn't been checked seriously. */
    549     for (int i = 2; i < real::BIGITS; i *= 2)
     547    for (int i = 1; i <= real::BIGITS; i *= 2)
    550548    {
    551549        ret = ret * (real::R_3 - ret * ret * x);
     
    669667        if (exponent <= 0)
    670668            ret.m_mantissa[i] = 0;
    671         else if (exponent < BIGIT_BITS)
    672             ret.m_mantissa[i] &= ~((1 << (BIGIT_BITS - exponent)) - 1);
    673 
    674         exponent -= BIGIT_BITS;
     669        else if (exponent < real::BIGIT_BITS)
     670            ret.m_mantissa[i] &= ~((1 << (real::BIGIT_BITS - exponent)) - 1);
     671
     672        exponent -= real::BIGIT_BITS;
    675673    }
    676674
Note: See TracChangeset for help on using the changeset viewer.