Adds two numbers.
Example: 5 and 3 -> 8, -2 and 7 -> 5
The two numbers
Their sum
Subtracts the second number from the first.
Example: 10 and 3 -> 7, 5 and 8 -> -3
The number to subtract from and the number to subtract
Their difference
Multiplies two numbers.
Example: 5 and 3 -> 15, -2 and 4 -> -8
The two numbers
Their product
Divides the first number by the second.
Dividing by 0 gives Infinity, as in JavaScript. Example: 10 and 2 -> 5, 7 and 2 -> 3.5
The number to divide and the number to divide by
Their quotient
Raises the first number to the power of the second.
Example: 2 to the 3 -> 8, 5 to the 2 -> 25, 10 to the -1 -> 0.1
The base and the exponent
The power
Finds the square root of a number.
A negative number gives NaN. Example: 9 -> 3, 2 -> 1.414
The number
The square root
Drops the sign of a number, so the result is never negative.
Example: -5 -> 5, 3 -> 3, 0 -> 0
The number
The absolute value
Rounds a number to the nearest whole number; halves round up.
Example: 3.7 -> 4, 2.3 -> 2, 5.5 -> 6
The number
The nearest whole number
Rounds a number down to the whole number below it.
Example: 3.7 -> 3, -2.3 -> -3, 5 -> 5
The number
The whole number below
Rounds a number up to the whole number above it.
Example: 3.2 -> 4, -2.8 -> -2, 5 -> 5
The number
The whole number above
Flips the sign of a number.
Example: 5 -> -5, -3 -> 3, 0 -> 0
The number
The number with the opposite sign
Finds the natural logarithm of a number: the power e must be raised to for that number.
Example: 2.718 -> about 1, 1 -> 0
The number, greater than 0
The natural logarithm
Finds the base-10 logarithm of a number: the power 10 must be raised to for that number.
Example: 100 -> 2, 1000 -> 3, 10 -> 1
The number, greater than 0
The base-10 logarithm
Raises 10 to the power of a number.
Example: 2 -> 100, 3 -> 1000, -1 -> 0.1
The exponent
10 to that power
Finds the sine of an angle given in radians.
Example: 0 -> 0, pi/2 -> 1
The angle in radians
The sine, between -1 and 1
Finds the cosine of an angle given in radians.
Example: 0 -> 1, pi -> -1
The angle in radians
The cosine, between -1 and 1
Finds the tangent of an angle given in radians.
Example: 0 -> 0, pi/4 -> about 1
The angle in radians
The tangent
Finds the angle, in radians, whose sine is the given number.
Example: 0 -> 0, 1 -> pi/2 (about 1.57)
A number between -1 and 1
The angle in radians
Finds the angle, in radians, whose cosine is the given number.
Example: 1 -> 0, -1 -> pi (about 3.14)
A number between -1 and 1
The angle in radians
Finds the angle, in radians, whose tangent is the given number.
Example: 0 -> 0, 1 -> pi/4 (about 0.785)
The number
The angle in radians, between -pi/2 and pi/2
Raises e, the base of the natural logarithm, to the power of a number.
Example: 0 -> 1, 1 -> about 2.718, 2 -> about 7.389
The exponent
e to that power
Converts an angle from degrees to radians.
Example: 180 -> pi (about 3.14159), 90 -> pi/2
The angle in degrees
The angle in radians
Converts an angle from radians to degrees.
Example: pi -> 180, pi/2 -> 90
The angle in radians
The angle in degrees
Passes a number through unchanged, so a value can be given a name and reused.
Example: 42 -> 42
The number
The same number
Gives a random number from 0 up to, but not including, 1.
Example: 0.342, 0.891 or any other value in that range
A random number between 0 and 1
Gives a random number between low and high.
Example: low 0, high 10 -> 3.7, 8.2 or any other value between them
The low and high ends of the range
A random number in the range
Gives a list of random numbers between low and high.
Example: low 0, high 10, count 3 -> [2.5, 7.1, 4.8]
The low and high ends of the range and how many numbers to make
The random numbers
Gives the constant pi, the ratio of a circle's circumference to its diameter.
Example: 3.141592653589793
The number pi
Applies one arithmetic operation to two numbers: add, subtract, multiply, divide, power or modulus.
The operation reads first then second: subtract gives first minus second, power gives
first to the power of second.
Example: 5 add 3 -> 8, 10 modulus 3 -> 1, 2 power 3 -> 8
The two numbers and the operation
The result of the operation
Finds the remainder after dividing one number by another.
The sign follows the first number, as it does in JavaScript. Example: 10 modulus 3 -> 1, 17 modulus 5 -> 2
The number to divide and the number to divide by
The remainder
Rounds a number to a given number of decimal places.
Example: 1.32156 to 3 places -> 1.322
The number and how many decimal places to keep
The rounded number
Rounds a number to a given number of decimal places and drops the zeros at the end.
As a number the result cannot carry trailing zeros anyway; the difference from
roundToDecimals is that floating-point noise such as 1.320000001 is cleaned to 1.32.
Example: 1.32156 to 3 places -> 1.322, 1.320000001 -> 1.32, 1.000 -> 1
The number and how many decimal places to keep
The rounded number
Applies one operation to a single number: absolute, negate, square root, rounding, logarithms, the trigonometric functions and their inverses, exponential, or a conversion between radians and degrees.
The trigonometric functions work in radians. Example: sqrt of 5 -> 2.236, absolute of -3 -> 3
The number and the operation
The result of the operation
Maps a number from one range onto another, keeping its relative position.
A number outside the source range maps proportionally beyond the target range. Example: 5 from [0,10] to [0,100] -> 50, 0.5 from [0,1] to [-10,10] -> 0
The number, the range it is in and the range to map it to
The number at the same relative position in the target range
Formats a number as text with a fixed number of decimal places, keeping trailing zeros.
Example: 3.14159 with 2 places -> '3.14', 5 with 3 places -> '5.000'
The number and how many decimal places to show
The formatted text
Maps a value from 0 to 1 onto the range min to max along an easing curve, so the result
speeds up or slows down instead of changing evenly.
An easeIn curve starts slowly, an easeOut curve ends slowly, an easeInOut curve does
both.
Example: 0.5 from [0,100] with easeInQuad -> 25
The value between 0 and 1, the target range and the easing curve
The eased value in the target range
Keeps a number within a range: below min becomes min, above max becomes max.
Example: 5 in [0,3] -> 3, -1 in [0,3] -> 0, 1.5 in [0,3] -> 1.5
The number and the range to keep it in
The number, limited to the range
Blends from a start value to an end value by a fraction t: 0 gives the start, 1 the end,
0.5 the midpoint.
A t outside 0 to 1 extrapolates past the ends.
Example: 0 to 100 at 0.5 -> 50, 10 to 20 at 0.25 -> 12.5
The start value, the end value and the fraction
The blended value
Finds where a value sits between a start and an end, as a fraction: the t that lerp would
need to produce it.
Example: 5 in [0,10] -> 0.5, 2.5 in [0,10] -> 0.25
The start value, the end value and the value to locate
The fraction from start to end
Turns a value from 0 to 1 into a smooth S-curve that starts and ends gently; the value is clamped to that range first.
Example: 0 -> 0, 0.5 -> 0.5, 0.25 -> 0.156
The value between 0 and 1
The smoothed value between 0 and 1
Tells the sign of a number: -1 when negative, 0 when zero, 1 when positive.
Example: -5 -> -1, 0 -> 0, 3.14 -> 1
The number
-1, 0 or 1
Keeps the part of a number after the decimal point, measured up from the whole number below it, so the result is always from 0 up to 1.
Example: 3.14 -> 0.14, -2.3 -> 0.7
The number
The fractional part, from 0 up to 1
Wraps a number into a range so it cycles round: past max it comes back in at min, and
below min it comes back in at max.
Useful for angles and repeating patterns; unlike a plain modulus it handles negative numbers. Example: 1.5 in [0,1) -> 0.5, -0.3 in [0,1) -> 0.7, 370 in [0,360) -> 10
The number and the range to wrap it into
The wrapped number, from min up to max
Bounces a value back and forth between 0 and length as t grows: up to length, back down
to 0, and again.
Example: length 1 at t 0.5 -> 0.5, t 1 -> 1, t 1.5 -> 0.5, t 2 -> 0
The running value and the length to bounce within
The bounced value between 0 and length
Moves a value toward a target by at most maxDelta, without overshooting it.
Example: 0 toward 10 by 3 -> 3, 8 toward 10 by 3 -> 10
The current value, the target and the largest step allowed
The value after one step
Works out a simple arithmetic expression written as text: numbers, +, -, the multiplication sign, /, parentheses and spaces.
The expression is parsed and computed by the library itself, never handed to the JavaScript engine to run, so it is safe with text a user typed. Example: '(3+2) times 4' written with the sign -> 20, '10/3' -> 3.3333
The expression text
The computed value
Arithmetic, rounding, ranges, random numbers and the trigonometric functions on plain numbers. The trigonometric functions take and give angles in radians;
degToRadandradToDegconvert at the boundary, because almost every angle a user types is in degrees. The interpolation helpers (lerp,remap,ease,smoothstep,pingPong) are the building blocks of animation and parametric variation.