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

# A translation of abs(x)

Started by Magmaramus, Jan 04 2012 05:23 AM

3 replies to this topic

### #1

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.

### #2

Posted 04 January 2012 - 05:45 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

If my posts contain broken links, try looking around my website. I gradually make blog posts for any examples I make.

### #3

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)

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)

YoYoGames | Youtube | Twitter | TheSnidr.com

### #4

Posted 03 March 2012 - 04:19 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:28 AM.**

pi = 3,1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679…