Game Development Community

MAbs not working?

by Martin Schultz · in Torque Game Engine Advanced · 09/05/2006 (12:43 am) · 5 replies

This morning I was trying to round a number in TSE (MS3) in script using mAbs(...) and it returned always the same non-rounded number to me. I looked then in the script docs I had on my notebook and that doc says mAbs should work like this:
%val = mAbs(76.3);
I fired up TSE and entered in the console
echo(  mAbs(76.3)  );
and it returned
76.3
What the hell did I do wrong? I would have expected a rounded 76 value instead of 76.3. Can someone please try this on their build? Maybe I screwed by build somehow.

Thanks,
Martin

#1
09/05/2006 (12:06 pm)
Uh, mAbs will return the absolute value of the number, not the rounded number. Try mFloor(), or mCeil().
#2
09/05/2006 (12:52 pm)
There's also a useful function called mFloatLength. I use that when I just need an integer.

ConsoleFunction( mFloatLength, const char *, 3, 3, "(float v, int numDecimals)"
"Return a string containing v formatted with the specified number of decimal places.")
#3
09/05/2006 (12:53 pm)
Oh, well, I thought mAbs would round a number. Seems like I'm wrong. But isn't there something that automatically rounds a number to the nearest integer value without doing manually a mFloor or mCeil?

Because for the numbers after the decimal point I would the have to check manually if it is below .5 and then do a mFloor and if it is .5 or higher do a mCeil. I thought there would be a function that does that stuff for me... :-)
#4
09/05/2006 (1:03 pm)
Ah, thanks Stefan. That answers my question :-)

And thanks Brian for your help.
#5
09/05/2006 (6:04 pm)
How about:

%rounded = mFloor ( %value +0.5)

No conditional logic needed and possibly more efficient than mFloatLength.