Re: Float comparison
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 08 May 2009 19:29:05 -0700
CBFalconer <cbfalconer@xxxxxxxxx> writes:
Keith Thompson wrote:
... snip ...
A stored value of type double cannot represent the real value
1.0+DBL_EPSILON/2.0, any more than a stored value of type int
can represent the value 1.5.
So what? doubles are used to store reals, more or less. ints are
used to store integers. 1.0+DBL_EPSILON/2.0 is a real[1]. 1.5 is
NOT an integer.
[1] but not a storable real, in a double.
It's that "more or less" that bites you, isn't it? Your model makes
some sense if you ignore those pesky details where it falls apart.
ints can only store a small subset of the set of integers. No
integers outside that subset can be stored in an int object. It
happens that the set of int values completely covers a range of
mathematical integers; that's one difference between ints as a subset
of integers and doubles as a subset of reals.
doubles can only store a small subset of the set of reals. No value
that's not in that subset can be stored in a double object.
Have you read C99 5.2.4.2.2 paragraphs 1-2? (In PDF or hard copy;
plain text doesn't show the formula.) Do you understand what it
means?
Please do not post a followup to this article without quoting and
responding to the previous paragraph, starting with "Have you read".
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: Float comparison
- From: Flash Gordon
- Re: Float comparison
- References:
- Re: Float comparison
- From: David Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- Prev by Date: Re: Create a Copy of Files
- Next by Date: Re: Create a Copy of Files
- Previous by thread: Re: Float comparison
- Next by thread: Re: Float comparison
- Index(es):
Relevant Pages
|