Math
Library for common mathematical functions.
- namespace Math
- const E
- const PI
- function abs(number)
- function arccos(ratio)
- function arcsin(ratio)
- function arctan(yComponent, xComponent)
- function cos(theta)
- function ensureRange(num, lowerBound, upperBound)
- function floor(number)
- function ln(number)
- function log10(number)
- function log2(number)
- function max(a, b)
- function min(a, b)
- function sign(num)
- function sin(theta)
- function tan(theta)
Constants
Name | Type | Value | Description |
---|---|---|---|
E | float | 2.718281828459045235360 | It's e. |
PI | float | 3.141592653589793238462 | It's pi. |
function abs(number)[link]
Returns the absolute value of the given numerical input. The type of the output will match the input.
Arguments
Name | Type | Description |
---|---|---|
number | float or integer | Any number |
Return Value
Type | Description |
---|---|
float or integer | A positive number |
function arccos(ratio)[link]
Calculates the arc cosine (inverse cosine) of the given ratio.
Arguments
Name | Type | Description |
---|---|---|
ratio | float | A valid cosine ratio. |
Return Value
Type | Description |
---|---|
float | the angle with the given cosine value in radians |
function arcsin(ratio)[link]
Calculates the arc sine (inverse sine) of the given ratio.
Arguments
Name | Type | Description |
---|---|---|
ratio | float | A valid sine ratio. |
Return Value
Type | Description |
---|---|
float | the angle with the given sine value in radians |
function arctan(yComponent, xComponent)[link]
Calculates the arc tangent (inverse tangent) of the given ratio. This function can be called with either 1 or 2 arguments. If given one argument, that value is the ratio and a theta between -pi / 2 and pi / 2will be returned. If given two arguments, these represent y and x components (respectively) of a vector. By providing two vector components, you will get return values in the full range of -pi to pi.
Arguments
Name | Type | Optional | Description |
---|---|---|---|
yComponent | float | A y-component value. |
|
xComponent | float | Optional | An optional x-component value. If ommitted, the default value is 1.0 and the first argument simply becomes a ratio. |
Return Value
Type | Description |
---|---|
float | the angle with the given tangent value |
function cos(theta)[link]
Computes the cosine of the given angle
Arguments
Name | Type | Description |
---|---|---|
theta | float | An angle in radians |
Return Value
Type | Description |
---|---|
float | The cosine ratio |
function ensureRange(num, lowerBound, upperBound)[link]
Ensures the number falls within the given range. The type of the output will match the number that is chosen. For example, ensureRange(2.0, 1, 3) will be 2.0, but ensureRange of (2, 0, 1) will be 1. If the number matches either the upper or lower bound, the initial input will be returned, so ensureRange(3.0, 3, 4) is unambiguously 3.0, not 3.
Arguments
Name | Type | Description |
---|---|---|
num | float or integer | Any number |
lowerBound | float or integer | The lower bound |
upperBound | float or integer | The upper bound |
Return Value
Type | Description |
---|---|
float or integer | A guaranteed to be in the given range. |
function floor(number)[link]
Returns the integer less than or equal to the given number.
Arguments
Name | Type | Description |
---|---|---|
number | float or integer | A float to round down. Integers are also valid input, but will return themselves. |
Return Value
Type | Description |
---|---|
integer | The next integer less than or equal to the input. |
function ln(number)[link]
Computes the natural logarithm (base e) of the input. Throws Core.InvalidArgumentException for values less than or equal to 0.
Arguments
Name | Type | Description |
---|---|---|
number | float or integer | A positive number |
Return Value
Type | Description |
---|---|
float | The natural logarithm |
function log10(number)[link]
Computes the base-10 logarithm of the input. Throws Core.InvalidArgumentException for values less than or equal to 0. Guaranteed to return floating-point-error-free floats for inputs that are exactly powers of 10.
Arguments
Name | Type | Description |
---|---|---|
number | float or integer | A positive number |
Return Value
Type | Description |
---|---|
float | The base 10 logarithm |
function log2(number)[link]
Computes the base-2 logarithm of the input. Throws Core.InvalidArgumentException for values less than or equal to 0. Guaranteed to return floating-point-error-free floats for inputs that are exactly powers of 2.
Arguments
Name | Type | Description |
---|---|---|
number | float or integer | A positive number |
Return Value
Type | Description |
---|---|
float | The base 2 logarithm |
function max(a, b)[link]
Returns the maximum of two numbers. The type of the output will match the number that is chosen. For example, max(3.0, 2) will be 3.0, but the max of (3, 2.0) will be 3. If they match, the first number is returned, so max(3.0, 3) is unambiguously 3.0, not 3.
Arguments
Name | Type | Description |
---|---|---|
a | float or integer | Any number |
b | float or integer | Any number |
Return Value
Type | Description |
---|---|
float or integer | The higher number. |
function min(a, b)[link]
Returns the minimum of two numbers. The type of the output will match the number that is chosen. For example, min(2.0, 3) will be 2.0, but the min of (2, 3.0) will be 2. If they match, the first number is returned, so min(3.0, 3) is unambiguously 3.0, not 3.
Arguments
Name | Type | Description |
---|---|---|
a | float or integer | Any number |
b | float or integer | Any number |
Return Value
Type | Description |
---|---|
float or integer | The lower number. |
function sign(num)[link]
Determines positive/negative/zero-ness of a number by returning -1, 0, or 1 accordingly. Output is always an integer regardless of input type.
Arguments
Name | Type | Description |
---|---|---|
num | float or integer | Any number |
Return Value
Type | Description |
---|---|
integer | -1 if the number is negative. 1 if it's positive. 0 if it's 0 or 0.0 |
function sin(theta)[link]
Computes the sine of the given angle
Arguments
Name | Type | Description |
---|---|---|
theta | float | An angle in radians |
Return Value
Type | Description |
---|---|
float | The sine ratio |
function tan(theta)[link]
Computes the tangent of the given angle.
Arguments
Name | Type | Description |
---|---|---|
theta | float | An angle in radians |
Return Value
Type | Description |
---|---|
float | The tangent ratio |