[Issue 3751] Optimalization error in some floating point code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 29 05:44:48 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3751


Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com


--- Comment #5 from Steven Schveighoffer <schveiguy at yahoo.com> 2010-01-29 05:44:47 PST ---
(In reply to comment #4)
> I'm not certain that there's a bug here (difficult to tell without reducing the
> test case further). It could be that in the optimised case you have a temporary
> value stored in a register, increasing the precision. It's legal for the
> compiler to do that. Adding a function call stops DMD from keeping the value in
> a register.
> Anyway you need to cut the test case down significantly.
> BTW it behaves the same way on DMD0.175, so this is definitely not a
> regression.

I think this is exactly the problem.  You are using floating point expecting
that all floats are created equal.

One rule about floating point is never to build an infinite loop waiting for
two floats to converge using ==.  You must use an epsilon if you expect any
reasonable result.

Your exit condition is this:

if (left == half || right == half)

What about trying this:

if(half - left < SOME_EPSILON || right - half < SOME_EPSILON)

where SOME_EPSILON is a very small insignificant number, like 0.000001

floating point convergence is an art form, you need to understand its
limitations.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list