|
Post by AxonMega on May 16, 2017 19:41:54 GMT
math.clamp is a way of setting boundaries for a number. It accepts three numerical parameters; x, min, and max. If x is less than min, then it returns min. If x is greater than max, then it returns max. Otherwise, it will return x. If max is less than min, it will throw an error.
Example:
print(math.clamp(2, 1, 10)) --> 2 print(math.clamp(0, 1, 10)) --> 1 print(math.clamp(11, 1, 10)) --> 10 math.sign is a way of finding out if a number is positive, negative, or neutral. It accepts one numerical parameter, x. It returns 1 if x is above 0, -1 if x is below 0, and 0 if x is 0.
Example:
print(math.sign(5)) --> 1 print(math.sign(-3)) --> -1 print(math.sign(0)) --> 0 Handy, no?
|
|
|
Post by Bit on May 16, 2017 19:53:15 GMT
Huh, that's nice.
|
|
|
Post by Josh on May 16, 2017 20:49:22 GMT
Seems good!
|
|
|
Post by goulstem on May 16, 2017 21:13:32 GMT
Neat yo
|
|
|
Post by disillusions on May 17, 2017 10:49:47 GMT
math.clamp: math.min(max,math.max(min,value))
math.sign: x ~= 0 and x/math.abs(x) or 0
|
|