This is the mail archive of the
mailing list for the GCC project.
Re: Fourth Draft "Unsafe fp optimizations" project description.
- To: kaih at khms dot westfalen dot de (Kai Henningsen)
- Subject: Re: Fourth Draft "Unsafe fp optimizations" project description.
- From: Joe Buck <jbuck at synopsys dot COM>
- Date: Wed, 15 Aug 2001 12:23:01 -0700 (PDT)
- Cc: ejr at cs dot berkeley dot edu, gcc at gcc dot gnu dot org
> ejr@CS.Berkeley.EDU (Jason Riedy) wrote on 12.08.01 in <200108130550.WAA23692@lotus.CS.Berkeley.EDU>:
> > For a simpler
> > view, does anyone really want to debug programs where
> > you cannot rely on equality?
> If there's one thing I've seen or heard in just about *every* discussion
> of computer floating point, it is that you cannot rely on equality. Just
> about every single one makes the point that with floating point, "A == B"
> is *wrong*, you want "abs(A-B) < some_small_value".
This is a common mistake made by intermediate programmers (beginners
make the mistake of using floating point equality inappropriately, people
with a bit of experience assume that therefore floating point equality
tests are always wrong).
In contexts like a fixed point class implemented on top of floating point,
the floating point operations compute exact results, and equality tests
make perfect sense (given constraints that can be determined by use of
the constants in <float.h>). Similarly, if a floating point variable has been
initialized to a known value on some control path, it will not mutate by
itself to value plus delta, and an equality test is much more efficient
than computing abs(A-B)<delta.