Skip to main content

API Reference

Classes

Math

Utility class for mathematical operations.

Static Functions

NameDescription
abs
Returns the absolute value of a number.
acos
Returns the inverse cosine (in radians) of a number.
acot
Calculates the inverse cotangent (acot) of a number.
acsc
Calculates the inverse cosecant (acsc) of a number.
arithmeticMean
Calculates the mean value of an array of numbers.
asec
Calculates the inverse secant (asec) of a number.
asin
Returns the inverse sine (in radians) of a number.
atan
Returns the inverse tangent (in radians) of a number.
atan2
Returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y), for Math.atan2(y, x).
ceil
Returns the smallest integer greater than or equal to a given number.
combinations
Calculates the number of combinations for choosing r items from a total of n items.
cos
Returns the cosine of a number in radians.
cot
Calculates the cotangent of an angle (in radians).
csc
Calculates the cosecant of an angle (in radians).
degreesToRadians
Convert degrees to radians.
factorial
Calculates the factorial of a given number.
fibonacci
Calculates the nth Fibonacci number.
floor
Returns the largest integer less than or equal to a given number.
geometricMean
Calculates the geometric mean of an array of numbers.
harmonicMean
Calculates the harmonic mean of an array of numbers.
hypot
Calculate the length of the vector from the origin to the point given by the coordinates.
isPrime
Checks if a number is prime.
log
Returns the natural logarithm (base e) of a number.
log10
Returns the base-10 logarithm of a number.
log2
Returns the base-2 logarithm of a number.
max
Returns the maximum value from an array of numbers.
median
Calculates the median value of an array of numbers.
min
Returns the minimum value from an array of numbers.
mode
Calculates the mode values of an array of numbers.
radiansToDegrees
Convert radians to degrees.
random
Generates a pseudo-random number between 0 and max (default of 1).
round
Rounds the given number to the nearest integer.
sec
Calculates the secant of an angle (in radians).
sign
Returns 1 or -1, indicating the sign of the number passed as an argument, 0 for 0.
sin
Returns the sine of a number in radians.
sqrt
Returns the square root of a number.
tan
Returns the tangent of a number in radians.
toRadix
Convert a value to a new number base.

abs
bring math;

math.abs(value: num);

Returns the absolute value of a number.

valueRequired
  • Type: num

The input number.


acos
bring math;

math.acos(value: num);

Returns the inverse cosine (in radians) of a number.

valueRequired
  • Type: num

A number between -1 and 1, inclusive, representing the angle's cosine value.


acot
bring math;

math.acot(value: num);

Calculates the inverse cotangent (acot) of a number.

valueRequired
  • Type: num

A number representing the cotangent value.


acsc
bring math;

math.acsc(value: num);

Calculates the inverse cosecant (acsc) of a number.

valueRequired
  • Type: num

A number equal or greater than |1|, representing the cosecant value.


arithmeticMean
bring math;

math.arithmeticMean(arr: MutArray<num>);

Calculates the mean value of an array of numbers.

arrRequired
  • Type: MutArray<num>

The array of numbers.


asec
bring math;

math.asec(value: num);

Calculates the inverse secant (asec) of a number.

valueRequired
  • Type: num

A number equal or greater than |1|, representing the secant value.


asin
bring math;

math.asin(value: num);

Returns the inverse sine (in radians) of a number.

valueRequired
  • Type: num

A number between -1 and 1, inclusive, representing the angle's sine value.


atan
bring math;

math.atan(value: num);

Returns the inverse tangent (in radians) of a number.

valueRequired
  • Type: num

A number.


atan2
bring math;

math.atan2(y: num, x: num);

Returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y), for Math.atan2(y, x).

yRequired
  • Type: num

The y coordinate of the point.


xRequired
  • Type: num

The x coordinate of the point.


ceil
bring math;

math.ceil(value: num);

Returns the smallest integer greater than or equal to a given number.

valueRequired
  • Type: num

The input number.


combinations
bring math;

math.combinations(n: num, r: num);

Calculates the number of combinations for choosing r items from a total of n items.

nRequired
  • Type: num

The total number of items.


rRequired
  • Type: num

The number of items to be chosen.


cos
bring math;

math.cos(value: num);

Returns the cosine of a number in radians.

valueRequired
  • Type: num

A number representing an angle in radians.


cot
bring math;

math.cot(value: num);

Calculates the cotangent of an angle (in radians).

valueRequired
  • Type: num

The angle in radians.


csc
bring math;

math.csc(value: num);

Calculates the cosecant of an angle (in radians).

valueRequired
  • Type: num

The angle in radians.


degreesToRadians
bring math;

math.degreesToRadians(degrees: num);

Convert degrees to radians.

degreesRequired
  • Type: num

Degree value.


factorial
bring math;

math.factorial(n: num);

Calculates the factorial of a given number.

nRequired
  • Type: num

The number to calculate the factorial for.


fibonacci
bring math;

math.fibonacci(n: num);

Calculates the nth Fibonacci number.

nRequired
  • Type: num

The position of the Fibonacci number to calculate.


floor
bring math;

math.floor(value: num);

Returns the largest integer less than or equal to a given number.

valueRequired
  • Type: num

The input number.


geometricMean
bring math;

math.geometricMean(arr: MutArray<num>);

Calculates the geometric mean of an array of numbers.

arrRequired
  • Type: MutArray<num>

The array of numbers.


harmonicMean
bring math;

math.harmonicMean(arr: MutArray<num>);

Calculates the harmonic mean of an array of numbers.

arrRequired
  • Type: MutArray<num>

The array of numbers.


hypot
bring math;

math.hypot(coordinates: MutArray<num>);

Calculate the length of the vector from the origin to the point given by the coordinates.

coordinatesRequired
  • Type: MutArray<num>

Array of coordinates.


isPrime
bring math;

math.isPrime(n: num);

Checks if a number is prime.

nRequired
  • Type: num

The number to check for primality.


log
bring math;

math.log(value: num);

Returns the natural logarithm (base e) of a number.

valueRequired
  • Type: num

The input number.


log10
bring math;

math.log10(value: num);

Returns the base-10 logarithm of a number.

valueRequired
  • Type: num

The input number.


log2
bring math;

math.log2(value: num);

Returns the base-2 logarithm of a number.

valueRequired
  • Type: num

The input number.


max
bring math;

math.max(arr: MutArray<num>);

Returns the maximum value from an array of numbers.

arrRequired
  • Type: MutArray<num>

The array of numbers.


median
bring math;

math.median(arr: MutArray<num>);

Calculates the median value of an array of numbers.

arrRequired
  • Type: MutArray<num>

The array of numbers.


min
bring math;

math.min(arr: MutArray<num>);

Returns the minimum value from an array of numbers.

arrRequired
  • Type: MutArray<num>

The array of numbers.


mode
bring math;

math.mode(arr: MutArray<num>);

Calculates the mode values of an array of numbers.

arrRequired
  • Type: MutArray<num>

The array of numbers.


radiansToDegrees
bring math;

math.radiansToDegrees(radians: num);

Convert radians to degrees.

radiansRequired
  • Type: num

Radians value.


random
bring math;

math.random(max?: num);

Generates a pseudo-random number between 0 and max (default of 1).

maxOptional
  • Type: num

The maximum value of the random number.


round
bring math;

math.round(value: num, options?: RoundingOptions);

Rounds the given number to the nearest integer.

valueRequired
  • Type: num

The number to be rounded.


optionsOptional

sec
bring math;

math.sec(value: num);

Calculates the secant of an angle (in radians).

valueRequired
  • Type: num

The angle in radians.


sign
bring math;

math.sign(value: num);

Returns 1 or -1, indicating the sign of the number passed as an argument, 0 for 0.

valueRequired
  • Type: num

The input number.


sin
bring math;

math.sin(value: num);

Returns the sine of a number in radians.

valueRequired
  • Type: num

A number representing an angle in radians.


sqrt
bring math;

math.sqrt(value: num);

Returns the square root of a number.

valueRequired
  • Type: num

A number greater than or equal to 0.


tan
bring math;

math.tan(value: num);

Returns the tangent of a number in radians.

valueRequired
  • Type: num

A number representing an angle in radians.


toRadix
bring math;

math.toRadix(value: num, base: num);

Convert a value to a new number base.

valueRequired
  • Type: num

The number to be converted.


baseRequired
  • Type: num

The base of the new value.


Constants

NameTypeDescription
E
numEuler's number, a mathematical constant approximately equal to 2.71828.
INF
numPositive infinity constant.
PI
numThe mathematical constant representing the ratio of a circle's circumference to its diameter.
TAU
numThe mathematical constant representing the ratio of a circle's circumference to the radius.

ERequired
E: num;
  • Type: num

Euler's number, a mathematical constant approximately equal to 2.71828.


INFRequired
INF: num;
  • Type: num

Positive infinity constant.


PIRequired
PI: num;
  • Type: num

The mathematical constant representing the ratio of a circle's circumference to its diameter.


TAURequired
TAU: num;
  • Type: num

The mathematical constant representing the ratio of a circle's circumference to the radius.


Structs

RoundingOptions

Options for rounding a number.

Initializer

bring math;

let RoundingOptions = math.RoundingOptions{ ... };

Properties

NameTypeDescription
decimalPlaces
numThe number of decimal places to round to.

decimalPlacesOptional
decimalPlaces: num;
  • Type: num

The number of decimal places to round to.