Class: Math

rune.util.Math()

The Math class contains a library of static methods for common mathematical calculations. The class can thus be used as an alternative to JavaScripts' built-in Math class.

Constructor

new Math()

Creates a new instance of the Math class. Note that this class is intended as a static library of methods, thus instantiation results in a warning.
Source:

Members

(static, constant) DEG_TO_RAD :number

Magic number used when converting between degrees to radians.
Type:
  • number
Default Value:
  • 0.01745329251
Source:

(static, constant) RAD_TO_DEG :number

Magic number used when converting between radians to degrees.
Type:
  • number
Default Value:
  • 57.2957795131
Source:

Methods

(static) abs(n) → {number}

Returns the absolute value of n.
Parameters:
Name Type Description
n number A number.
Source:
Returns:
The absolute value of the given number.
Type
number

(static) avg(n) → {number}

Returns the mean of n.
Parameters:
Name Type Description
n Array A list of numbers.
Source:
Returns:
The mean of given numbers.
Type
number

(static) ceil(n) → {number}

Returns the smallest integer greater than or equal to n.
Parameters:
Name Type Description
n number A number.
Source:
Returns:
The smallest integer greater than or equal to the given number.
Type
number

(static) chance(n) → {boolean}

Returns true based on a chance of n.
Parameters:
Name Type Description
n number Chance between 0 and 100.
Source:
Returns:
True or false, depending on the chance of n.
Type
boolean

(static) clamp(num, min, max) → {number}

Returns a number within a specified range.
Parameters:
Name Type Description
num number A number.
min number Minimum number.
max number Maximum number.
Source:
Returns:
A number between the minimum and maximum value.
Type
number

(static) cos(n) → {number}

Returns the cosine of n.
Parameters:
Name Type Description
n number The angle in radians for which to return the cosine.
Source:
Returns:
The cosine of the given number.
Type
number

(static) degreesToRadians(angle) → {number}

Converts an angle in degrees to radians.
Parameters:
Name Type Description
angle number Angle described in degrees.
Source:
Returns:
Specified angle in radians.
Type
number

(static) diff(a, b) → {number}

Calculates the difference between a and b.
Parameters:
Name Type Description
a number A number.
b number A number.
Source:
Returns:
The difference between a and b.
Type
number

(static) distance(x1, y1, x2, y2) → {number}

Returns the distance between two points.
Parameters:
Name Type Description
x1 number The x coordinate of the first point.
y1 number The y coordinate of the first point.
x2 number The x coordinate of the second point.
y2 number The y coordinate of the second point.
Source:
Returns:
The distance between the first and second points.
Type
number

(static) floor(n) → {number}

Returns the largest integer less than or equal to n.
Parameters:
Name Type Description
n number A number.
Source:
Returns:
A number representing the largest integer less than or equal to the specified number.
Type
number

(static) formatBytes(bytes, decimals) → {string}

Returns a human-friendly string representation of a quantity specified in bytes.
Parameters:
Name Type Description
bytes number Number of bytes.
decimals number Number of decimals.
Source:
Returns:
Human-friendly string representation.
Type
string

(static) isEven(n) → {boolean}

Returns whether n is an even number (true) or not (false).
Parameters:
Name Type Description
n number A number.
Source:
Returns:
Whether a given number is even.
Type
boolean

(static) isNum(n) → {boolean}

Checks whether n is a number. The method does not consider "special values" like NaN or Infinity as numbers; they must be digit-based, either positive or negative.
Parameters:
Name Type Description
n number | undefined A number.
Source:
Returns:
Whether n is an number.
Type
boolean

(static) isOdd(n) → {boolean}

Returns whether n is an odd number (true) or not (false).
Parameters:
Name Type Description
n number A number.
Source:
Returns:
Whether a given number is odd.
Type
boolean

(static) isPowerOfTwo(n) → {boolean}

Returns whether a number is power of two (true) or not (false).
Parameters:
Name Type Description
n number A number.
Source:
Returns:
Whether a given number is power of two.
Type
boolean

(static) percentDec(num, max) → {number}

Returns the percentage (as float) of a specified number.
Parameters:
Name Type Description
num number A number.
max number Maximum number.
Source:
Returns:
Percentage of given numbers.
Type
number

(static) percentInc(num, max) → {number}

Returns the percentage (as integer) of a specified number.
Parameters:
Name Type Description
num number A number.
max number Maximum number.
Source:
Returns:
Percentage of given numbers.
Type
number

(static) radiansToDegrees(radians) → {number}

Converts an angle in radians to degrees.
Parameters:
Name Type Description
radians number Angle described in radians.
Source:
Returns:
Specified angle in degrees.
Type
number

(static) random(minopt, maxopt) → {number}

Returns a random floating point number.
Parameters:
Name Type Attributes Description
min number <optional>
Minimum number.
max number <optional>
Maximum number.
Source:
Returns:
A random number between the minimum and maximum value.
Type
number

(static) randomInt(minopt, maxopt) → {number}

Returns a random integer.
Parameters:
Name Type Attributes Description
min number <optional>
Minimum number.
max number <optional>
Maximum number.
Source:
Returns:
A random number between the minimum and maximum value.
Type
number

(static) sin(n) → {number}

Returns the sine of n.
Parameters:
Name Type Description
n number A number (given in radians).
Source:
Returns:
The sine of the given number.
Type
number

(static) wrap(num, min, max) → {number}

Returns a number within a specified range.
Parameters:
Name Type Description
num number A number.
min number Minimum number.
max number Maximum number.
Source:
Returns:
A number between the minimum and maximum value.
Type
number