Re: Float comparison
- From: Flash Gordon <smap@xxxxxxxxxxxxxxxxx>
- Date: Sun, 10 May 2009 10:30:25 +0100
CBFalconer wrote:
Flash Gordon wrote:Keith Thompson wrote:... snip ...CBFalconer <cbfalconer@xxxxxxxxx> writes:
<snip>So what? doubles are used to store reals, more or less. intsIt's that "more or less" that bites you, isn't it? Your model
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.
makes some sense if you ignore those pesky details where it
falls apart.
In addition doubles *are* used to store exact integral values
and integer types *are* used to store approximations. Any claim
that you have stored a range when you have in fact stored the
exact value that you intended to store is clearly wrong and would
make error analysis impossible.
So what? You are referring to the programming that is using that
object. I am talking about what you can deduce from the object in
isolation.
That value isThe point is, that taken in isolation you do NOT know that it is a range. Taken in isolation you only know what the actual stored value is. is a single exact value specified by a well-defined model which may represent either an exact quantity or a range which could be (and ofen is) far larger than the ranges you are talking about.
The standard actually talks about values that "can be represented exactly" in section 6.3.1.5 (paragraph 2).
The standard also states that the set of values of the style float is a subset of the values of type double. This can only be true if they are not ranges as you are describing since the range 0.00001 to 0.00002 is not the same as the range 0.000001 to 0.000002 (I know those are not really ranges in your model, but they are easy to type) so with your model they can be almost completely disjoint sets (infinities and NaNs may be the only point of intersection). This is in 6.2.5 paragraph 10 which /defines/ real floating types.
So various pieces of wording in the C standard are inconsistent with your claim that the values stored are always approximations. They are, however, entirely consistent with the branch of mathematics known as set theory which allows you do have whatever sets you want.
--
Flash Gordon
.
- Follow-Ups:
- Re: Float comparison
- From: CBFalconer
- 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
- From: Keith Thompson
- Re: Float comparison
- From: Flash Gordon
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- Prev by Date: Re: how to pass float value from argv?
- Next by Date: Re: Float comparison
- Previous by thread: Re: Float comparison
- Next by thread: Re: Float comparison
- Index(es):
Relevant Pages
|