Experiencing a strange problem using the modulus operator.
Inside a function I have the following code:
var vValue1 = passed_MC._x - this.Maze_Horizontal_offset;
var vValue2 = 36;
var vTheResult = vValue1 % vValue2;
trace (vValue1 = + vValue1);
trace (vTheResult = + Number(vTheResult));
Because _x is not necessarily an integer, vValue1 is not guaranteed to
be an integer either, which it must be for modulo to return the result
you want. Force it to be with
var vValue1 = Math.round(passed_MC._x - this.Maze_Horizontal_offset);
and it should work as you expect.
Helen
--
Experiencing a strange problem using the modulus operator.
Inside a function I have the following code:
var vValue1 = passed_MC._x - this.Maze_Horizontal_offset;
var vValue2 = 36;
var vTheResult = vValue1 % vValue2;
trace (vValue1 = + vValue1);
trace (vTheResult = + Number(vTheResult));
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Strange behaviour from modulus operator
Because _x is not necessarily an integer, vValue1 is not guaranteed to
be an integer either, which it must be for modulo to return the result
you want. Force it to be with
var vValue1 = Math.round
How much closer to zero where you expecting? 5 to the power of 10 to the
-14 is zero to the limits of modern PCs.
If you want to deal with integers make the numbers integers. If you do
your math in floating point with a mantissa with lots of bits, you are
going to get some bits left over at
5 matches
Mail list logo