Interesting math result - bug?
by Kevin Ryan · in Torque Game Engine · 08/20/2002 (6:22 pm) · 3 replies
Here is the small script code fragment:
and here is the result:
So am I missing something here that explains this result?
$TRT = 8.82;
$TRT = ($TRT * 1000) % 1000000;
echo("1st TRT: " @ $TRT);
$TRT = 8.82;
$TRT = $TRT * 1000;
$TRT = $TRT % 1000000;
echo("2nd TRT: " @ $TRT);and here is the result:
1st TRT: 8819 2nd TRT: 8820
So am I missing something here that explains this result?
#2
I would bet it's due to the value being stored to the global in the second case, and to a temporary value in the first. As a guess, I thiink that it's probably the modulo operator that's giving you trouble - I bet it's rounding the number in some way.
Do you get the same results without the multiplication by a thousand? (Don't have Torque handy to try myself)
04/15/2003 (11:12 pm)
Don't do your finances in TorqueScript ;)I would bet it's due to the value being stored to the global in the second case, and to a temporary value in the first. As a guess, I thiink that it's probably the modulo operator that's giving you trouble - I bet it's rounding the number in some way.
Do you get the same results without the multiplication by a thousand? (Don't have Torque handy to try myself)
#3
Of course, if you already know Python ... you should look into TGEPython by Joshua Ritter.
Actually, I'm planning on making a resource for my J and TGE integration project ... but I have to get all the kinks out first. :D
Alex
04/15/2003 (11:53 pm)
Im currently integrating the J Language into TGE for my game. My objective for doing so was to be able to do better and simpler (of course this is relative) array/vector/matrix calculations from both C++ and TorqueScript.Of course, if you already know Python ... you should look into TGEPython by Joshua Ritter.
Actually, I'm planning on making a resource for my J and TGE integration project ... but I have to get all the kinks out first. :D
Alex
Torque Owner Nathan Martin
TRON 2001 Network