Christian Christmann wrote:
Hi,
just a general question.
Which data type is more precise for large values:
float or double?
Thank you.
Chris
Hi Chris
First of all, your question is somewhat off-topic to this newsgroup. AFAIK,
the precision of C++ floating point data types is platform-dependent and
not a language subject. You would get a better answer if you posted your
question in a numerical analysis group you would get better answers than in
this newsgroup.
Still, here are my 0.02?
The float data type and the double data types are floating point data types.
A floating point data type is a digital representation of a number, which
aims to be equivalent to a real number.
Physically, a floating point data type is a set of bits which is divided
into sections (ranges of bits in the bit set). Two of those bit sections
are the significand and the exponent parts of the number. If the size of
the data type increases, the bits available to be allocated to the
significand section and to the exponent section also increase. So, if the
data type gets bigger, it also increases it's precision and it's range.
So, to finally answer your question, being the size of the double data type
usually bigger than the size of the float, then the precision of the double
data type should be greater than the precision of the float data type. But
have in mind that in the end this is all platform-dependent and not a
language issue.
for a light introduction check out the wikipedia article:
http://en.wikipedia.org/wiki/Floating_point
Hope this helps
Rui Maciel
--
Running Kubuntu 5.04 with KDE 3.4.2 and proud of it.
jabber:ru********@jabber.org