This has to do with the fact
that not every decimal value can be exactly
represented by a binary floating point.  So the results
of adding a bunch of binary numbers that is not exact 
to begin with will come out to be
different than the actual binary floating point for 0.8.

You can either turn the comparison into an integral
one as some has proposed or introduce 
an absolute error (epsilon) into the comparison:

if (Math.abs(i - 0.8) < 0.00001) trace("here");


- boon
  

Hans Wichman <[EMAIL PROTECTED]> wrote:  Hi peeps,
related discussions have been on here before, but i didn't find a real answer.
Imagine this piece of code:
var i = 0;

onEnterFrame = function () {
 i = i + 0.1;
 trace (i);
 if (i == 0.7) trace("here");
}

as you might expect, after running for 7 frames, it traces "here".
However if you change 0.7 to 0.8, it stops working.

I assume this is to floating point math and rounding errors and stuff?
In what way can i check for equality to 0.7 then? With a bigger than, 
smaller than construction?

This seems so weird to me...

greetz
Hans

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



                
---------------------------------
 Yahoo! Personals
 Let fate take it's course directly to your email.
 See who's waiting for you Yahoo! Personals
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to