Author Topic: [RESOURCE] Functions That Should Be Default (but Aren't)  (Read 6250 times)

-snip-

Clarify it better without losing conciseness. Would you want to see this pop up in your IDE?

"This function, which is defined in TorqueScript, is an extension to the default getRandom(); functionality, and allows for getting a floating point value number between two given limits. It should be used when a number, which may or may not be an integer, is desired within a given range."

Thank you for providing such a perfect example of what this thread ISN'T for.

what?

blah
No, you just have to change the description to this:
// Returns a random float within two limits.

function mRound(%num) {
   return mFloatLength(%num, 0);
}

I use this:

function mRound(%num)
{
   return mFloor(%num + 0.5);
}


Nexus uses the same method.

I use this:

function mRound(%num)
{
   return mFloor(%num + 0.5);
}


Nexus uses the same method.

And... why?

And... why?
On this forum I've seen many people just use mFloatLength(%num,0) or a few other ways
But the way jes posted is a default console function provided in later versions of the engine

And... why?

How about you stop being a condescending ass and actually communicate properly.

How about you stop being a condescending ass and actually communicate properly.
you couldn't of said it better.

mFloor(%x + 0.5) is actually the proper way of rounding, believe it or not. If port thinks that's some sort of convoluted way of doing it then he's absolutely wrong.

How about you stop being a condescending ass and actually communicate properly.

Where the hell did that come from? I asked jes00 why he preferred to use that method, that's it. Calm down.

mFloor(%x + 0.5) is actually the proper way of rounding, believe it or not. If port thinks that's some sort of convoluted way of doing it then he's absolutely wrong.

One of several 'proper' ways of rounding.

One of several 'proper' ways of rounding.
Okay, and what other method would YOU prefer, exactly?

Okay, and what other method would YOU prefer, exactly?

Either the method mentioned above (floor(... + 1)) or mFloatLength(<value>, 0)—both are commonly used ways of rounding numbers.

Where the hell did that come from? I asked jes00 why he preferred to use that method, that's it. Calm down.
Yeah but the way you worded it sounded a but condescending. Clearly I'm not the only one who thought that

Either the method mentioned above (floor(... + 1)) or mFloatLength(<value>, 0)—both are commonly used ways of rounding numbers.

I don't understand this then:

And... why?

If you know it's a commonly used method, why are you asking?
« Last Edit: June 15, 2014, 01:04:14 PM by Greek2me »

He's asking why you would bother creating a function for something that already exists in Torque. It'd likely be faster just to define mRound as a macro for mFloatLength( x , 0 ) rather than use Torque's stuffty math system to add 0.5 and then floor. But there's no point to that, just type the extra letters out for mFloatLength.