Torquescript can't really do accurate integer math over 999,999
by Orion Elenzil · in Torque Game Engine · 11/08/2006 (3:39 pm) · 5 replies
Just discovered this:
when converting integers to strings, Torque uses scientific notation for any number larger than 999,999.
eg:
echo(999998 + 1);
999999
echo(999998 + 2);
1e+006
echo(999998 + 3);
1e+006
which leads to:
echo(mFloor(999998 + 3) - mFloor(999998 + 2));
0
when converting integers to strings, Torque uses scientific notation for any number larger than 999,999.
eg:
echo(999998 + 1);
999999
echo(999998 + 2);
1e+006
echo(999998 + 3);
1e+006
which leads to:
echo(mFloor(999998 + 3) - mFloor(999998 + 2));
0
About the author
#2
The trick is to modify the dSprintf calls in these functions:
getDataTypeF32 ()
getFloatArg ()
CompilerStringTable::addFloatString ()
setFloatValue ()
11/08/2006 (3:52 pm)
This has been documented before.The trick is to modify the dSprintf calls in these functions:
getDataTypeF32 ()
getFloatArg ()
CompilerStringTable::addFloatString ()
setFloatValue ()
#3
In any case, here's the thread I was thinking about incase this fix is not in. Though the solution in that very thread has some flaws with floating point numbers, the basic solution is there and with some modifications it will work just fine.
11/08/2006 (3:53 pm)
I think Orion and c.o are running 1.3 so that might explain it.In any case, here's the thread I was thinking about incase this fix is not in. Though the solution in that very thread has some flaws with floating point numbers, the basic solution is there and with some modifications it will work just fine.
#4
this is in tge 1.3.
thanks for the quick replies.
hmm, not sure what to do for 1.3.
the only one of those methods which are actually being called in echo(999999 + 1) is setFloatValue(),
which is getting in 1000000.0000000 and the %g in dSprintf() is converting to scientific notation.
I'm sure there's some modifier to %g to determine at what value to switch to scientific. I'll look into it. thanks guys. And i'll drop John a line.
11/08/2006 (3:58 pm)
Oops, should have included my version.this is in tge 1.3.
thanks for the quick replies.
hmm, not sure what to do for 1.3.
the only one of those methods which are actually being called in echo(999999 + 1) is setFloatValue(),
which is getting in 1000000.0000000 and the %g in dSprintf() is converting to scientific notation.
I'm sure there's some modifier to %g to determine at what value to switch to scientific. I'll look into it. thanks guys. And i'll drop John a line.
#5
Since this isn't really affecting us at present, and it sounds like the possibility of weird side-effects from the fix is still lingering around, i'll probably just note this as a Thing To Watch Out For.
11/08/2006 (4:05 pm)
Thanks again for the link, Stefan.Since this isn't really affecting us at present, and it sounds like the possibility of weird side-effects from the fix is still lingering around, i'll probably just note this as a Thing To Watch Out For.
Associate Matt Fairfax
PopCap
We've encountered this "bug" a few times when making games. I thought we had rolled the fix into 1.4.2 but it could have easily slipped through the cracks. John Quigley is the one who fixed the bug for us so you may want to email him about it.