Math Functions

Math Functions



Built-in Functions on the Math Namespace


pow

Raises the first argument to the power of the second argument.

int i = Math:pow(2, 8);




sqrt

Calculates the square root of the argument.

decimal d = Math:sqrt(3);




random

Generates a random decimal between 0 and 1.

decimal r = Math:random(); 




ceil

Returns the smallest value that is greater than or equal to the argument and is equal to a mathematical integer.

// 93.00
decimal c = Math:ceil(92.31);

// 93
int c = Math:ceil(92.31);




floor

Returns the largest value that is less than or equal to the argument and is equal to a mathematical integer.

// 92.00
decimal f = Math:floor(92.31);

// 92
int f = Math:floor(92.31);






round

Operates on a decimal value to return a rounded decimal value with the specified scale and rounding method applied.

The rounding method is optional and, if not supplied, a default method of DSL_MATH_ROUNDING_METHOD.Half_Up will be applied.

// Rounding method specified
// 3.12
decimal r = Math:round(3.125, 2, DSL_MATH_ROUNDING_METHOD.Half_Down);

// Rounding method defaults to DSL_MATH_ROUNDING_METHOD.Half_Up
// 3.13
decimal r = Math:round(3.125, 2);

Available rounding methods are defined in the following built-in enum:

enum DSL_MATH_ROUNDING_METHOD {
	Up, Down, Ceiling, Floor, Half_Up, Half_Down, Half_Even, Unnecessary
}




Additional Mentions and References