Float Comparison Returns False

Jonathan M Davis jmdavisProg at gmx.com
Thu Jul 7 18:40:03 PDT 2011


On 2011-07-07 17:28, bearophile wrote:
> Loopback:
> > I do want to ask though what an alternative would be in this case, to
> > compare the two different values. You mentioned something about
> > "epsilons" but I have no experience within this field. I would really
> > appreciate an example or something similar so I could understand your
> > statement.
> 
> If you want to use floating point values in your programs then you probably
> need to know something about floating point representation. This is a good
> starting point: http://en.wikipedia.org/wiki/Floating_point
> For your problem there is the feqrel function:
> http://www.digitalmars.com/d/2.0/phobos/std_math.html#feqrel
> 
> > From what I can see these are two identical values, I would be more than
> > 
> > glad if someone could explain just what is the difference between these
> > two "non-equal" values and how make them "equal". Perhaps I should use
> > ints and long instead since they don't seem to suffer from this
> > "problem"?
> 
> Generally in a program you use floating point values only if you can't use
> integral values (and you don't want to go toward fixed point values,
> rationals, etc).

What Every Computer Scientist Should Know About Floating-Point Arithmetic:

http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list