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

# A translation of abs(x)

Started by Magmaramus, Jan 04 2012 05:09 AM

3 replies to this topic

### #1

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.

### #2

Posted 04 January 2012 - 05:31 AM

Normally, if you'd want this in script, you would do:

if (argument0 < 0) return -argument0 return argument0Or 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

### #3

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)

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)

### #4

Posted 03 March 2012 - 04:05 PM

I've found out this:

a mod b = a - b*floor(a/b)

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