Modulo with real numbers (decimals)
by Tom Bak · in Torque Game Builder · 08/04/2007 (12:14 pm) · 0 replies
Hi,
I've noticed that the modulo operation will return a truncated value if you use it with real numbers.
For example
will output 1 instead of 1.5...
This can lead to inaccuracies and weird behavior...
For example, when updating a rotation value I like to mod it with 360 in the end so that the result stays within the range [0,360)... If I'm calculating a fractional rotation value and then I mod it, the fractional part goes away and my result is not as accurate... :P
I can compensate by manually calculating mod (x%y = x - (y*mFloor(x/y))) but it's not intuitive... I'm thinking maybe other people are experiencing subtle problems with this and may not know why their numbers are coming out inaccurate.
How does everyone else feel about this??? ;)
Tom
I've noticed that the modulo operation will return a truncated value if you use it with real numbers.
For example
echo(1.5 % 5);
will output 1 instead of 1.5...
This can lead to inaccuracies and weird behavior...
For example, when updating a rotation value I like to mod it with 360 in the end so that the result stays within the range [0,360)... If I'm calculating a fractional rotation value and then I mod it, the fractional part goes away and my result is not as accurate... :P
I can compensate by manually calculating mod (x%y = x - (y*mFloor(x/y))) but it's not intuitive... I'm thinking maybe other people are experiencing subtle problems with this and may not know why their numbers are coming out inaccurate.
How does everyone else feel about this??? ;)
Tom