Math

Description

The Javascript Math namespace.

Function List

Function Documentation

allFlags(flags, mask)

Check if all the bits in a given mask have been set in a flag variable.

Parameters

flags:The set of flags to examine.

mask:The bitmask to check against flags.

Returns

true if all the bits set in mask were also set in flags, false otherwise.

Remarks

Always returns false if mask == 0.

anyFlags(flags, mask)

Check if any of the bits in a given mask have been set in a flag variable.

Parameters

flags:The set of flags to examine.

mask:The bitmask to check against flags.

Returns

true if any of the bits set in mask were also set in flags, false otherwise.

Remarks

Always returns false if mask == 0.

clamp(val, min, max)

Clamps a value between two bounds.

Parameters

val:The value to clamp.

min:The minimum value to accept.

max:The maximum value to accept.

Returns

val, if val was between min and max. max, if val was greater than max. min, if val was less than min.

isInteger(val)

Determines if a value is an integer.

Parameters

val:The value to examine.

Returns

true if val == parseInt(Number(val)), false otherwise.

Remarks

Always returns false if val is undefined, null or isNaN(val) == true.

isZero(val)

Quickly check if a value is small enough to consider it as being zero for practical purposes.

Parameters

val:A value to check for zero-ness.

Returns

true if val was within +/- 1E-06 of 0.0, false otherwise.

randomInt(min, max)

Get a randomly-generated integer between two bounds (inclusively).

Parameters

min:The minimum value to generate.

max:The maximum value to generate.

Returns

A random integer between the given bounds, inclusive.

serp(start, end, val)

Interpolates between two values using a sine wave.

Parameters

start:The starting value (when val == 0.0).

end:The final value (when val == 1.0).

val:The value used for interpolation.

Returns

A value along a sine wave between the start and end values.

Remarks

For a neat start-finish interpolation, val should be clamped between 0.0 and 1.0 but since sine is cyclical this is not essential.

trueRound(val, digits)

Precise rounding to a fixed number of digits.

Parameters

val:The value to round.

digits:The number of digits to round val to.

Returns

A string containing val rounded to the specified number of digits.

Remarks

More information: Stack Overflow: round off decimal using javascript