Ignore:
Timestamp:
Sep 28, 2011, 7:04:44 PM (11 years ago)
Author:
sam
Message:

core: implement shift operators for reals; they're useful for fast
multiplications by integers, especially powers of two.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/real.cpp

    r993 r994  
    349349    real tmp = *this;
    350350    return *this = tmp / x;
     351}
     352
     353real real::operator <<(int x) const
     354{
     355    real tmp = *this;
     356    return tmp <<= x;
     357}
     358
     359real real::operator >>(int x) const
     360{
     361    real tmp = *this;
     362    return tmp >>= x;
     363}
     364
     365real &real::operator <<=(int x)
     366{
     367    if (m_signexp << 1)
     368        m_signexp += x;
     369    return *this;
     370}
     371
     372real &real::operator >>=(int x)
     373{
     374    if (m_signexp << 1)
     375        m_signexp -= x;
     376    return *this;
    351377}
    352378
     
    542568    }
    543569
    544     /* FIXME: sum.m_signexp += 2; (but needs private data access) */
    545     sum *= (real)4;
    546     return z * sum;
     570    return z * (sum << 2);
    547571}
    548572
Note: See TracChangeset for help on using the changeset viewer.