SUGGESTION: Math.Abs function

Started by monkey0506, Tue 08/05/2007 16:52:24

Previous topic - Next topic

monkey0506

I know it's pretty basic to set this up, but it would be nice if AGS had a built-in method for calculating absolute value. I'm envisioning something like Math.Abs(float) because we could then use it properly with floats and for integers we could just pass in IntToFloat(X).

Workaround
Code: ags
// script header:
import float abs(float value);

// main script
float abs(float value) {
  if (value < 0.0) return -value;
  return value;
  }


Basically it would just be nice if say, a module writer wanted to use it in more than one of their modules they wouldn't have to duplicate the function...besides how hard would it really be to implement into AGS*? ;)

*I know Chris is updating the Editor right now for v2.8, but how about for v2.9 Beta 1 eh?

Khris

While we're at it, the logarithm would be a nice addition, too.
I've coded it once, but I guess that's much slower than a built-in function would be.


Pumaman

Sounds reasonable, if anyone else agrees?

monkey0506

Again, I can see how this would probably be considered as a pretty low-priority request, but then I imagine it would take all of about 10 or 15 minutes to fully implement as well as document. 8)

SupSuper

Sure, the more Math functions, the better. They all eventually become essential to coding. :)

While we're at it, some kind of "Nth root" would be nice. Square root is a bit limited.
Programmer looking for work

deltamatrix

BAD WOLF - TORCHWOOD - MR SAXON - THE BEES ARE DISAPPEARING - PANDORICA - RIVER SONG

Gilbert

Quote from: SupSuper on Fri 11/05/2007 21:33:49
While we're at it, some kind of "Nth root" would be nice. Square root is a bit limited.

Just use Maths.RaiseToPower()...

Like Maths.RaiseToPower(100.0, 1.0/3.0) for example.

SMF spam blocked by CleanTalk