MANUAL / SCRIPTING & EXPRESSIONS

Math and conversion (expressions)

Math functions and constants, and converting between numbers and strings.

Math functions

FunctionNotes
Math.abs, acos, asin, atan, ceil, cos, exp, floor, sin, sqrt, tan, trunc, signOne number.
Math.logNatural log. Also Math.log10, Math.log2.
Math.roundRounds .5 up, as JavaScript does.
Math.atan2(y, x), Math.pow(a, b)Two numbers.
Math.hypot, Math.max, Math.minAny number of numbers.
Math.random()0–1, repeatable per frame.

Angles in Math functions are radians; use degreesToRadians() / radiansToDegrees().

Constants

Math.PI, Math.E, Math.LN2, Math.LN10, Math.LOG2E, Math.LOG10E, Math.SQRT2, Math.SQRT1_2.

Conversion

FunctionWhat it does
Number(x)A number from a string or true/false; anything else gives NaN.
String(x)Text from a value.
isNaN(x)true if x isn't a number.
n.toFixed(d)A number as text with d decimals (0–20).
s.toUpperCase(), s.toLowerCase()

Examples

// bob up and down
value + [0, Math.sin(time * 2 * Math.PI) * 20]

// round a slider for display
Math.round(effect("Slider Control")("Slider"))