Re: Float comparison



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.

.



Relevant Pages

  • Re: [OT] Re: The real Dawkins on TV...
    ... > your foundational texts are worthless; that your 'miracles' are imaginary; ... Nor is it a matter of 'ideology' to oppose the ... > that results from the indulgence of 'religious faith' isn't in any sense ...
    (talk.origins)
  • Re: An alternative view of our lads
    ... I wonder why he took this turn after years of more measured approach which was lighter on analysis. ... information on that man's website and I often turn up his site when Googling obscure bands. ... I'll snip it, but you're attributes seem out of character with the site I've visited. ... any revisions still don't matter to me as it didn't before. ...
    (rec.music.beatles)
  • [OT] Re: Open Source -> Unemployment
    ... Otkrivsi radosti NEWS-a John Doe odluci da sa svima podeli svoje misli: ... > going to get glossed over in the pile of resumes, no matter how ...
    (comp.unix.programmer)
  • Re: Postings to sci.geo.satellite-nav
    ... whilst criticizing us for doing the same. ... or toss the entire thread into a single post. ... I can tell you that no matter which choice you make, ... The argument if you snip is that some people don't want to go up 20 ...
    (sci.geo.satellite-nav)
  • Re: Isotope decay chains
    ... >> HUP, AFAIK. ... > matter is very definit or else nothing in our worlsd of matter ... is well known to physicists (please don't stick to ...
    (sci.physics)