Re: Float comparison
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Wed, 13 May 2009 21:15:58 -0400
Keith Thompson wrote:
.... snip ...
If an int object i contains the value 42, it doesn't matter
whether it was generated via
int i = 42;
or
int i = 6 * 7;
or
int i = 429 / 10;
The meaning of the stored value 42 is independent of how it was
generated.
If a double object x contains the value 42.0, it doesn't matter
how it was generated. The meaning of 42.0 is independent of how
it was generated.
No, it isn't. To quote the standard again:
5.2.4.2.2:
... snip ...
[#10] The values given in the following list shall be
replaced by implementation-defined constant expressions with
(positive) values that are less than or equal to those
shown:
-- the difference between 1 and the least value greater
than 1 that is representable in the given floating
point type, b1-p
FLT_EPSILON 1E-5
DBL_EPSILON 1E-9
LDBL_EPSILON 1E-9
and your double object can be representing anything fom
42*(1-DBL_EPSILON) though 42*(1+DBL_EPSILON). (typical). Without
detailed examination of the code you can't tell anything more. The
standard specifies the makeup of a fp value in terms of
significand, sign, and exponent. That forces all the 'ranges' to
consist of 'touching' real values, and ensures that no real value
can belong to more than one 'range'. That is the magic that
enables the sensible use of <, >, <=, >= conditions, but not ==.
Yes, I am creating another critical name, 'touching'.
Note that a 'range' consists of real values, and any interval of
real values contains an infinite number of values. There is only
one value of the fp object, so the odds of its accuracy are
negligible. This has nothing to do with the C standard, but with
mathematics.
There is continuous confusion here from confusing the value
represented by the fp object, and the number stored in the fp
object. They are probably different.
....
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
.
- Follow-Ups:
- Re: Float comparison
- From: Flash Gordon
- Re: Float comparison
- From: William Pursell
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- References:
- 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: 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: 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: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- Prev by Date: Re: Truth value
- Next by Date: Re: print 64bit-integer
- Previous by thread: Re: Float comparison
- Next by thread: Re: Float comparison
- Index(es):
Relevant Pages
|