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 the end. The machine is doing all of its math in binary and some/many decimal numbers can not be represented exactly in binary. Think of 1/3+1/3+1/3 != .33+.33+.33 It is not just machines that have the problem.

You can never compare a floating point number to zero and expect your code to work reliably. Convert the result of modulus to an integer and compare that to 0.


Ron




Paul Steven wrote:
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));

And here are the results I am getting from the trace statements:

vValue1 = 324
vTheResult = 5.6843418860808e-14

----------------

Surely it should give me a result of zero as 36 goes into 324 exactly 9
times.

The weird thing is if I just hard code the values as follows, it works

var vValue1 = 324;
var vValue2 = 36;

var vTheResult =  vValue1 %  vValue2;

trace ("vTheResult = " + Number(vTheResult));

-----------------

And here is the result of the trace statement:

vTheResult = 0

I am therefore totally confused!!!

Any help much appreciated. I am publishing for Flash 7 with Actionscript 1.0

Thanks

Paul


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to