This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Precision
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Feodor Pisnitchenko <feodor at mat dot ufpr dot br>, gcc-help at gcc dot gnu dot org
- Date: Sun, 21 Dec 2003 18:46:34 -0600
- Subject: 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.]