Re: Precision

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Feodor,

#include <iostream>
    using std::cout;
    using std::endl;

template <typename FP>
int MantissaBitSize(FP one)
{
    int rv = 1;
    FP fXeno = one / 2;
    FP fLast = one;
    FP f = one + fXeno;

    while(f != fLast)
    {
        fLast = f;
        fXeno = fXeno / 2;
        fLast = f + fXeno;
        ++rv;
    }

    return rv;
}

int main()
{
    cout << "float      : " << MantissaBitSize(1.0f) << endl;
    cout << "double     : " << MantissaBitSize(1.0 ) << endl;
    cout << "long double: " << MantissaBitSize(1.0l) << endl;
}

HTH,
--Eljay

[Non-HTML encoded, this time.  Sorry about that.] 


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux