Math

Math functions.

Members

static constant Math.EPSILON1 : Number

0.1

static constant Math.EPSILON2 : Number

0.01

static constant Math.EPSILON3 : Number

0.001

static constant Math.EPSILON4 : Number

0.0001

static constant Math.EPSILON5 : Number

0.00001

static constant Math.EPSILON6 : Number

0.000001

static constant Math.EPSILON7 : Number

1e-7

static constant Math.EPSILON8 : Number

1e-8

static constant Math.EPSILON9 : Number

1e-9

static constant Math.EPSILON10 : Number

1e-10

static constant Math.EPSILON11 : Number

1e-11

static constant Math.EPSILON12 : Number

1e-12

static constant Math.EPSILON13 : Number

1e-13

static constant Math.EPSILON14 : Number

1e-14

static constant Math.EPSILON15 : Number

1e-15

Methods

static Math.clamp(value, min, max)Number

Constraint a value to lie between two values.

Name Type Description
value Number

The value to clamp.

min Number

The minimum value.

max Number

The maximum value.

Returns:

The clamped value such that min <= result <= max.

static Math.equalsEpsilon(left, right, relativeEpsilon, absoluteEpsilon)Boolean

Determines if two values are equal using an absolute or relative tolerance test. This is useful to avoid problems due to roundoff error when comparing floating-point values directly. The values are first compared using an absolute tolerance test. If that fails, a relative tolerance test is performed. Use this test if you are unsure of the magnitudes of left and right.

Name Type Default Description
left Number

The first value to compare.

right Number

The other value to compare.

relativeEpsilon Number 0 optional

The maximum inclusive delta between left and right for the relative tolerance test.

absoluteEpsilon Number relativeEpsilon optional

The maximum inclusive delta between left and right for the absolute tolerance test.

Returns:

true if the values are equal within the epsilon; otherwise, false.

Example:
const a = equalsEpsilon(0.0, 0.01, EPSILON2); // true
const b = equalsEpsilon(0.0, 0.1, EPSILON2);  // false
const c = equalsEpsilon(3699175.1634344, 3699175.2, EPSILON7); // true
const d = equalsEpsilon(3699175.1634344, 3699175.2, EPSILON9); // false

static Math.lerp(p, q, time)Number

Computes the linear interpolation of two values.

Name Type Description
p Number

The start value to interpolate.

q Number

The end value to interpolate.

time Number

The time of interpolation generally in the range [0.0, 1.0].

Returns:

The linearly interpolated value.

Example:
const n = Math.lerp(0.0, 2.0, 0.5); // returns 1.0

static Math.toDegrees(radians)Number

Converts radians to degrees.

Name Type Description
radians Number

The angle to convert in radians.

Returns:

The corresponding angle in degrees.

static Math.toRadians(degrees)Number

Converts degrees to radians.

Name Type Description
degrees Number

The angle to convert in degrees.

Returns:

The corresponding angle in radians.