Skip to main content

API Reference

Classes

Math

Utility class for mathematical operations.

Static Functions

NameDescription
absReturns the absolute value of a number.
acosReturns the inverse cosine (in radians) of a number.
acotCalculates the inverse cotangent (acot) of a number.
acscCalculates the inverse cosecant (acsc) of a number.
arithmeticMeanCalculates the mean value of an array of numbers.
asecCalculates the inverse secant (asec) of a number.
asinReturns the inverse sine (in radians) of a number.
atanReturns the inverse tangent (in radians) of a number.
atan2Returns 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).
ceilReturns the smallest integer greater than or equal to a given number.
combinationsCalculates the number of combinations for choosing r items from a total of n items.
cosReturns the cosine of a number in radians.
cotCalculates the cotangent of an angle (in radians).
cscCalculates the cosecant of an angle (in radians).
degreesToRadiansConvert degrees to radians.
factorialCalculates the factorial of a given number.
fibonacciCalculates the nth Fibonacci number.
floorReturns the largest integer less than or equal to a given number.
geometricMeanCalculates the geometric mean of an array of numbers.
harmonicMeanCalculates the harmonic mean of an array of numbers.
hypotCalculate the length of the vector from the origin to the point given by the coordinates.
isPrimeChecks if a number is prime.
maxReturns the maximum value from an array of numbers.
medianCalculates the median value of an array of numbers.
minReturns the minimum value from an array of numbers.
modeCalculates the mode values of an array of numbers.
radiansToDegreesConvert radians to degrees.
randomGenerates a pseudo-random number between 0 and max (default of 1).
roundRounds the given number to the nearest integer.
secCalculates the secant of an angle (in radians).
sinReturns the sine of a number in radians.
sqrtReturns the square root of a number.
tanReturns the tangent of a number in radians.

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.


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.


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.


Constants

NameTypeDescription
EnumEuler's number, a mathematical constant approximately equal to 2.71828.
INFnumPositive infinity constant.
PInumThe mathematical constant representing the ratio of a circle's circumference to its diameter.
TAUnumThe 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
decimalPlacesnumThe number of decimal places to round to.

decimalPlacesOptional
decimalPlaces: num;
  • Type: num

The number of decimal places to round to.