JavaScript Math related methods
Methods
-
static average(values) → {float}
-
Calculates the average value in a list
Parameters:
Name Type Description values
Number | Array.<Number> values Returns:
float - The average value -
static clamp(values, minopt, maxopt) → {Number|Array.<Number>}
-
Clamps the value
Parameters:
Name Type Attributes Default Description values
Number | Array.<Number> values min
Number <optional>
0 The minimum value max
Number <optional>
1 The maximum value Returns:
Number | Array.<Number> - The clamped values -
static compare(value1, value2, floatPrecisionopt) → {boolean}
-
Compares two numbers
Parameters:
Name Type Attributes Default Description value1
Number The first value value2
Number The second value floatPrecision
int <optional>
-1 The precision for (float) number comparison, number of decimals. Set to -1 to not use. Returns:
boolean - true if the two values are equal -
static getLength(value1, value2) → {float}
-
Measures the vector length between two points
Parameters:
Name Type Description value1
Array.<int> The first value value2
Array.<int> The second value Returns:
float - The length -
static log10(w) → {float}
-
Calculates the log10 of a number
Parameters:
Name Type Description w
float The number Returns:
float - The result of log10(x)
i.e. Math.log(x)/Math.LN10 -
static random(minopt, maxopt) → {int}
-
Generates a random integer between minimum and maximum
Parameters:
Name Type Attributes Default Description min
int <optional>
0 The minimum value max
int <optional>
1 The maximum value Returns:
int - The randomly generated integer -
static toDegrees(value) → {float}
-
Converts the number from radians to degrees
Parameters:
Name Type Description value
number the value Returns:
float - The value in degrees -
static toDegrees(value) → {float}
-
Converts the number from radians to degrees
Parameters:
Name Type Description value
number the value Returns:
float - The value in degrees -
static toRadians(value) → {float}
-
Converts the number from degrees to radians
Parameters:
Name Type Description value
number the value Returns:
float - The value in radians -
static toRadians(value) → {float}
-
Converts the number from degrees to radians
Parameters:
Name Type Description value
number the value Returns:
float - The value in radians