* Re: Precision
[not found] <Pine.LNX.4.21.0312182104580.28834-100000@newton.mat.ufpr.b r>
@ 2003-12-22 0:46 ` Eljay Love-Jensen
0 siblings, 0 replies; 2+ messages in thread
From: Eljay Love-Jensen @ 2003-12-22 0:46 UTC (permalink / raw)
To: Feodor Pisnitchenko, gcc-help
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.]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Precision
@ 2003-12-18 23:11 Feodor Pisnitchenko
0 siblings, 0 replies; 2+ messages in thread
From: Feodor Pisnitchenko @ 2003-12-18 23:11 UTC (permalink / raw)
To: gcc-help
Hi all!
How can I find out the precision (mantissa length) of a floating point
number in i386 architecture?
I don't understand the output the following program (why long double and
double have the same mantissa length?)
#include <iostream>
using namespace std;
int main() {
float c3;
double c2;
long double c1;
c3=1.1234567890123456789012345678901234567890123456789012345678901234567890;
c2=1.1234567890123456789012345678901234567890123456789012345678901234567890;
c1=1.1234567890123456789012345678901234567890123456789012345678901234567890;
cout.precision(50);
cout << "long double c1 = " << c1 << " " << sizeof(c1) << endl;
cout << " double c2 = " << c2 << " " << sizeof(c2) << endl;
cout << " float c3 = " << c3 << " " << sizeof(c3) << endl;
}
output:
long double c1 = 1.1234567890123456912476740399142727255821228027344 12
double c2 = 1.1234567890123456912476740399142727255821228027344 8
float c3 = 1.12345683574676513671875 4
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-12-22 0:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <Pine.LNX.4.21.0312182104580.28834-100000@newton.mat.ufpr.b r>
2003-12-22 0:46 ` Precision Eljay Love-Jensen
2003-12-18 23:11 Precision Feodor Pisnitchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).