Re: wprintf() and large exact floats?
- From: "David Webber" <dave@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 9 Apr 2008 00:23:28 +0100
"Vincent Fatica" <vince@xxxxxxxxxxxxxxxxx> wrote in message news:47fbe50a$1@xxxxxxxxxxxxxxxxxxxx
2^57 can be (and is) exactly represented as a double...
It is almost always a mistake to think of floating point representations to a fixed number of decimals as "exact". To be exact a decimal needs to specify an infinite number of decimal places. If you think of a number with an infinite number of trailing zeroes after (say) 16 specified significant figures as being "exactly" represented, then you'll end up in trouble more often than not. (The idea that the trailing digits, beyond those stored by the computer, must be zero, is a poor one. Think of them as unknown.)
In decimal representations 2.0 2.00 2.000 2.0000 are different objects, each of which is a number known to lie in a (different) range around the integer 2.
Computers of course cannot make this distinction at this level, but the problem does come in at around the 16th significant figure for doubles.
The point is that you have no right to assume that arithmetic involving floating point representations can ever be exact.
If you want to store an integer exactly, then do not use floating point types.
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
.
- Follow-Ups:
- Re: wprintf() and large exact floats?
- From: Vincent Fatica
- Re: wprintf() and large exact floats?
- References:
- wprintf() and large exact floats?
- From: Vincent Fatica
- wprintf() and large exact floats?
- Prev by Date: Re: wprintf() and large exact floats?
- Next by Date: Re: wprintf() and large exact floats?
- Previous by thread: Re: wprintf() and large exact floats?
- Next by thread: Re: wprintf() and large exact floats?
- Index(es):
Relevant Pages
|