# A translation of abs(x)

3 replies to this topic

### #1 Magmaramus

Magmaramus

GMC Member

• New Member
• 67 posts
• Version:GM8

Posted 04 January 2012 - 05:09 AM

I came up with this in math class today. It's probably useless but I'm posting it anyway.

`abs(x) = x * (sign(x));`

• 0

### #2 YellowAfterlife

YellowAfterlife

GMC Member

• Global Moderators
• 3491 posts
• Version:GM:Studio

Posted 04 January 2012 - 05:31 AM

Normally, if you'd want this in script, you would do:
```if (argument0 < 0) return -argument0
return argument0```
Or in some gm-specific way:
```var n;
n = (argument0 < 0)
return (n * -argument0) + (!n * +argument0)```
Or even more gm-specific way:
`return ((argument0 >= 0) - 0.5) * 2 * argument0`

• 0

### #3 TheSnidr

TheSnidr

That guy

• Global Moderators
• 2436 posts
• Version:GM:Studio

Posted 04 January 2012 - 12:49 PM

Absolute values are generally calculated like this:
1 dimension - abs(x)=sqrt(sqr(x))
2 dimensions - abs(x,y)=sqrt(sqr(x)+sqr(y))
3 dimensions - abs(x,y,z)=sqrt(sqr(x)+sqr(y)+sqr(z))
Though, as square root is rather slow, it's better to use the already built in functions:
Abs(x)
Point_distance(x1,y1,x2,y2)
Point_distance_3d(bleh)
• 0

### #4 Digisynth

Digisynth

GMC Member

• Validating
• 55 posts

Posted 03 March 2012 - 04:05 PM

I've found out this:
a mod b = a - b*floor(a/b)

Edited by Digisynth, 04 March 2012 - 10:14 AM.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users