Math
Mathematical functions and constants. Accessed via Math.method() in KrunkScript.
Availability: Client & Server
Methods
- abs
- acos
- acosh
- asin
- asinh
- atan
- atan2
- atanh
- calcPerc
- ceil
- cos
- cosh
- E
- exp
- floor
- hypot
- lerp
- log
- max
- min
- PI
- PI2
- pow
- round
- roundDecimal
- roundToNearest
- sin
- sinh
- sqrt
- tan
- tanh
- toDeg
- toRad
- trunc
MATH.abs
client server
Return the absolute value of a number.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.abs(0);
MATH.acos
client server
Compute the arccosine (inverse cosine) of a value. Returns radians.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.acos(0);
MATH.acosh
client server
Compute the inverse hyperbolic cosine of a value.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.acosh(0);
MATH.asin
client server
Compute the arcsine (inverse sine) of a value. Returns radians.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.asin(0);
MATH.asinh
client server
Compute the inverse hyperbolic sine of a value.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.asinh(0);
MATH.atan
client server
Compute the arctangent (inverse tangent) of a value. Returns radians.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.atan(0);
MATH.atan2
client server
Compute the angle between the positive X axis and the point (x, y). Returns radians.
Signature: num action(num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Y coordinate |
y | num | X coordinate |
Returns: num
num result = Math.atan2(0, 10);
MATH.atanh
client server
Compute the inverse hyperbolic tangent of a value.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.atanh(0);
MATH.calcPerc
client server
Calculate a percentage of a number (num * perc / 100).
Signature: num action(num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
num | num | The number |
perc | num | Percentage value |
Returns: num
num result = Math.calcPerc(0, 0);
MATH.ceil
client server
Round a number up to the nearest integer.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.ceil(0);
MATH.cos
client server
Compute the cosine of an angle (in radians).
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.cos(0);
MATH.cosh
client server
Compute the hyperbolic cosine of a value.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.cosh(0);
MATH.E
client server
Euler's number (approximately 2.718). Mathematical constant.
Type: num (constant)
num val = Math.E;
MATH.exp
client server
Compute e raised to the power of x.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.exp(0);
MATH.floor
client server
Round a number down to the nearest integer.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.floor(0);
MATH.hypot
client server
Compute the square root of the sum of squares of the arguments.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
values | num | Numbers to compare |
Returns: num
num result = Math.hypot(0);
MATH.lerp
client server
Linearly interpolate between two values by a factor (0-1).
Signature: num action(num, num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Start value |
y | num | End value |
z | num | Interpolation factor (0-1) |
Returns: num
num result = Math.lerp(0, 10, 0);
MATH.log
client server
Compute the natural logarithm (base e) of a value.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.log(0);
MATH.max
client server
Return the largest of the given numbers.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
values | num | Numbers to compare |
Returns: num
num result = Math.max(0);
MATH.min
client server
Return the smallest of the given numbers.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
values | num | Numbers to compare |
Returns: num
num result = Math.min(0);
MATH.PI
client server
The ratio of a circle's circumference to its diameter (approximately 3.14159).
Type: num (constant)
num val = Math.PI;
MATH.PI2
client server
Two times PI (full circle in radians, approximately 6.28318).
Type: num (constant)
num val = Math.PI2;
MATH.pow
client server
Compute x raised to the power of y.
Signature: num action(num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Base |
y | num | Exponent |
Returns: num
num result = Math.pow(0, 10);
MATH.round
client server
Round a number to the nearest integer.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.round(0);
MATH.roundDecimal
client server
Round a number to a specified number of decimal places.
Signature: num action(num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
num | num | The number to round |
places | num | Number of decimal places |
Returns: num
num result = Math.roundDecimal(0, 0);
MATH.roundToNearest
client server
Round a number to the nearest multiple of a given value.
Signature: num action(num, num)
Parameters:
| Name | Type | Description |
|---|---|---|
num | num | The number to round |
near | num | Round to nearest multiple of this value |
Returns: num
num result = Math.roundToNearest(0, 0);
MATH.sin
client server
Compute the sine of an angle (in radians).
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.sin(0);
MATH.sinh
client server
Compute the hyperbolic sine of a value.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.sinh(0);
MATH.sqrt
client server
Compute the square root of a value.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.sqrt(0);
MATH.tan
client server
Compute the tangent of an angle (in radians).
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.tan(0);
MATH.tanh
client server
Compute the hyperbolic tangent of a value.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.tanh(0);
MATH.toDeg
client server
Convert radians to degrees.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.toDeg(0);
MATH.toRad
client server
Convert degrees to radians.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.toRad(0);
MATH.trunc
client server
Remove the fractional part of a number.
Signature: num action(num)
Parameters:
| Name | Type | Description |
|---|---|---|
x | num | Numeric value |
Returns: num
num result = Math.trunc(0);