Skip to main content

Number functions

Manipulate numbers.


clamp()

Clamps number within the inclusive lower and upper bounds.

clamp(number, lower, upper)

Arguments

number (Number)
The number to clamp.
lower (Number)
The lower bound.
upper (Number)
The upper bound.

Returns

(Number)
The clamped number.

Examples

InputExpressionResult
[]
clamp(-10, -5, 5)
-5
[]
clamp(10, -5, 5)
5

epsilon()

Returns the smallest positive numeric value representable in JavaScript.

epsilon()

Returns

(Number)
The epsilon number.

Examples

InputExpressionResult
[]
epsilon()
2.220446049250313e-16

in_range()

Checks if number is between start and up to, but not including, end. If start is greater than end the params are swapped to support negative ranges.

in_range(number, start, end)

Arguments

number (Number)
The number to check.
start (Number)
The start of the range.
end (Number)
The end of the range.

Returns

(Number)
true if number is in the range, else false.

Examples

InputExpressionResult
[]
in_range(3, 2, 4)
true
[]
in_range(`1.2`, 0, 2)
true
[]
in_range(-3, -2, -6)
true
[]
in_range(2, 0, 2)
false

max_number()

Returns the maximum numeric value representable in JavaScript.

max_number()

Returns

(Number)
The max number.

Examples

InputExpressionResult
[]
max_number()
1.7976931348623157e308

max_safe_integer()

Returns the maximum safe integer in JavaScript (2^53 - 1).

max_safe_integer()

Returns

(Number)
The maximum safe integer number.

Examples

InputExpressionResult
[]
max_safe_integer()
9007199254740991

min_number()

Returns the smallest positive numeric value representable in JavaScript.

min_number()

Returns

(Number)
The min number.

Examples

InputExpressionResult
[]
min_number()
5e-324

min_safe_integer()

Returns the minimum safe integer in JavaScript (-(2^53 - 1)).

min_safe_integer()

Returns

(Number)
The minimum safe integer number.

Examples

InputExpressionResult
[]
min_safe_integer()
-9007199254740991

negative_infinity()

Returns the negative Infinity value.

negative_infinity()

Returns

(Number)
The negative Infinity number.

Examples

InputExpressionResult
[]
multiply(max_number(), -2) == negative_infinity()
true

positive_infinity()

Returns the positive Infinity value.

positive_infinity()

Returns

(Number)
The positive Infinity number.

Examples

InputExpressionResult
[]
multiply(max_number(), 2) == positive_infinity()
true

random()

Produces a random number between the inclusive lower and upper bounds. If floating is true, or either lower or upper are floats, a floating-point number is returned instead of an integer.

random(lower, upper, floating)

Arguments

lower (Number)
The lower bound.
upper (Number)
The upper bound.
floating (Boolean)
Specify returning a floating-point number.

Returns

(Number)
The random number.

Examples

InputExpressionResult
[0, 5]
random([0], [1], false)
3
[0, 5]
random([0], [1], true)
4.855003277326469
[1.2, 5.2]
random([0], [1], true)
2.4858320623111396