Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: monkey0506 on Tue 08/05/2007 16:52:24

Title: SUGGESTION: Math.Abs function
Post by: monkey0506 on Tue 08/05/2007 16:52:24
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
// 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?
Title: Re: SUGGESTION: Math.Abs function
Post by: Khris on Tue 08/05/2007 17:03:35
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.

Title: Re: SUGGESTION: Math.Abs function
Post by: Pumaman on Tue 08/05/2007 19:59:57
Sounds reasonable, if anyone else agrees?
Title: Re: SUGGESTION: Math.Abs function
Post by: monkey0506 on Wed 09/05/2007 17:18:05
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)
Title: Re: SUGGESTION: Math.Abs function
Post by: SupSuper on Fri 11/05/2007 21:33:49
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.
Title: Re: SUGGESTION: Math.Abs function
Post by: deltamatrix on Sat 12/05/2007 16:01:50
Math.max
Math.min

;D ;D
Title: Re: SUGGESTION: Math.Abs function
Post by: Gilbert on Sat 12/05/2007 17:43:50
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.