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:23 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
• 4157 posts
• Version:GM:Studio

Posted 04 January 2012 - 05:45 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
If my posts contain broken links, try looking around my website. I gradually make blog posts for any examples I make.

#3 TheSnidr

TheSnidr

Heavy metal viking dentist

• GMC Elder
• 3345 posts
• Version:GM:Studio

Posted 04 January 2012 - 01:03 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:19 PM

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

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

pi = 3,1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679…