This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Precision


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]