class Primitives · Computations
Values
Arithmetic on reactive numbers: add, subtract, multiply, divide, modulus, round, clamp, interpolate and remap.
Static methods
absstatic
addstatic
static add(value1: Real | NumberLike, value2: Real | NumberLike, result?: Real | null): RealAdds two real values.
value1- The first operand.
value2- The second operand.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The sum of value1 and value2.
ceilstatic
static ceil(value: Real | NumberLike, result?: Real | null): RealReturns the smallest integer value greater than or equal to the specified real number.
value- The value to round up.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The ceiling of value.
clampstatic
static clamp(value: Real | NumberLike, min: Real | NumberLike, max: Real | NumberLike, result?: Real | null): RealClamps a value to the inclusive range [min, max].
value- The value to clamp.
min- The lower bound of the range.
max- The upper bound of the range.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns value if it lies within the range; otherwise the nearest bound. If min is greater than max, the result is max.
dividestatic
static divide(value1: Real | NumberLike, value2: Real | NumberLike, result?: Real | null): RealDivides one real value by another.
value1- The dividend.
value2- The divisor.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The result of dividing value1 by value2.
floorstatic
static floor(value: Real | NumberLike, result?: Real | null): RealReturns the largest integer value less than or equal to the specified real number.
value- The value to round down.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The floor of value.
inverseLerpstatic
static inverseLerp(a: Real | NumberLike, b: Real | NumberLike, value: Real | NumberLike, result?: Real | null): RealComputes the inverse of a linear interpolation, returning the factor t such that Lerp(a, b, t) == value.
a- The start of the range, corresponding to
t = 0. b- The end of the range, corresponding to
t = 1. value- The value within the range to invert.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The interpolation factor that maps a–b to value. Returns 0 if a equals b.
isNearlyEqualstatic
static isNearlyEqual(value1: Real | NumberLike, value2: Real | NumberLike, tolerance: Real | NumberLike, result?: Bool | null): BoolDetermines whether two real values are equal within a specified tolerance.
value1- The first value.
value2- The second value.
tolerance- The maximum allowed difference for the values to be considered equal.
resultoptional- Optional
Boolto write the result into; it is returned. Without it, a newBoolis returned.
Returns true if the absolute difference between the values is at most tolerance; otherwise false.
isZerostatic
lerpstatic
static lerp(value1: Real | NumberLike, value2: Real | NumberLike, t: Real | NumberLike, result?: Real | null): RealLinearly interpolates between two real values by the specified factor.
value1- The start value, returned when
tis 0. value2- The end value, returned when
tis 1. t- The interpolation factor.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The value interpolated between value1 and value2 at t.
maxstatic
static max(value1: Real | NumberLike, value2: Real | NumberLike, result?: Real | null): RealReturns the larger of two real values.
value1- The first value.
value2- The second value.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The larger of value1 and value2.
minstatic
static min(value1: Real | NumberLike, value2: Real | NumberLike, result?: Real | null): RealReturns the smaller of two real values.
value1- The first value.
value2- The second value.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The smaller of value1 and value2.
modulusstatic
static modulus(value1: Real | NumberLike, value2: Real | NumberLike, result?: Real | null): RealComputes the modulus (remainder) of two real values.
value1- The dividend.
value2- The divisor.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The remainder of value1 divided by value2, with the sign of value1 (7.5 mod 2 = 1.5, −7.5 mod 2 = −1.5); NaN if value2 is 0.
multiplystatic
static multiply(value1: Real | NumberLike, value2: Real | NumberLike, result?: Real | null): RealMultiplies two real values.
value1- The first operand.
value2- The second operand.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The product of value1 and value2.
negatestatic
powerstatic
static power(baseVal: Real | NumberLike, exponent: Real | NumberLike, result?: Real | null): RealRaises a base value to the specified exponent.
baseVal- The base.
exponent- The exponent.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns baseVal raised to the power of exponent.
remapstatic
static remap(value: Real | NumberLike, fromMin: Real | NumberLike, fromMax: Real | NumberLike, toMin: Real | NumberLike, toMax: Real | NumberLike, result?: Real | null): RealRemaps a value from one range to another.
value- The value to remap.
fromMin- The lower bound of the source range.
fromMax- The upper bound of the source range.
toMin- The lower bound of the target range.
toMax- The upper bound of the target range.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns value mapped from [fromMin, fromMax] into [toMin, toMax]. Returns toMin if the source range has zero width.
roundstatic
static round(value: Real | NumberLike, result?: Real | null): RealRounds a real value to the nearest integer. Halves are rounded up (2.5 -> 3, -2.5 -> -2), like JavaScript's Math.round.
value- The value to round.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns value rounded to the nearest integer.
signstatic
static sign(value: Real | NumberLike, result?: Real | null): RealReturns the sign of a real value as −1, 0, or 1.
value- The value to evaluate.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns −1 if value is negative, 0 if zero, or 1 if positive.
smoothstepstatic
static smoothstep(edge0: Real | NumberLike, edge1: Real | NumberLike, value: Real | NumberLike, result?: Real | null): RealApplies a smooth Hermite interpolation between 0 and 1 over the range [edge0, edge1].
Returns 0 for values at or below edge0 and 1 for values at or above edge1.
edge0- The lower edge of the interpolation range.
edge1- The upper edge of the interpolation range.
value- The value to evaluate.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns A smoothly interpolated value in [0, 1].
sqrtstatic
static sqrt(value: Real | NumberLike, result?: Real | null): RealComputes the square root of a real value.
value- The value to compute the square root of. Must be non-negative.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The positive square root of value.
sqrtScalestatic
static sqrtScale(value: Real | NumberLike, maxValue: Real | NumberLike, maxSize: Real | NumberLike, result?: Real | null): RealA size whose square is proportional to the value: sqrt(value / maxValue) * maxSize. As the
radius of a circle or the side of a square, the area is proportional to the value, and
maxValue gets maxSize.
Values ≤ 0 give 0. Values above maxValue give more than maxSize (no clamping). NaN if
maxValue is not positive and finite.
value- The value, e.g. a population.
maxValue- The value that gets
maxSize, usually the largest one. maxSize- The size for
maxValue, e.g. the largest radius. resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The size for value.
subtractstatic
static subtract(value1: Real | NumberLike, value2: Real | NumberLike, result?: Real | null): RealSubtracts one real value from another.
value1- The value to subtract from.
value2- The value to subtract.
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns The result of value1 minus value2.
wrapstatic
static wrap(value: Real | NumberLike, min: Real | NumberLike, max: Real | NumberLike, result?: Real | null): RealWraps a value into the range [min, max] using modular arithmetic. Unlike clamp, values
that exceed the range wrap around to the other end.
value- The value to wrap.
min- The lower bound of the range (inclusive).
max- The upper bound of the range (exclusive).
resultoptional- Optional
Realto write the result into; it is returned. Without it, a newRealis returned.
Returns value wrapped into [min, max). Returns min if the range has zero width.
