FlowscopeDocs

math reference

Numeric helpers and constants.

math.* functions are pure and work anywhere. A null argument gives a null result unless noted.

Functions

math.abs

Flowscope Script
math.abs(value: number) -> same_numeric

Returns the absolute value of a number.

value keeps its type: an int returns an int and a float returns a float. Check for null or use ?? to supply a fallback before calling. Null float inputs produce null.

ParameterType
valuenumber

Returns same_numeric

math.acos

Flowscope Script
math.acos(value: float) -> float?

Returns the arccosine of a float in radians.

value must be in [-1.0, 1.0] for a real result. Values outside that range return null. Check for null before calling.

ParameterType
valuefloat

Returns float?

math.asin

Flowscope Script
math.asin(value: float) -> float?

Returns the arcsine of a float in radians.

value must be in [-1.0, 1.0] for a real result. Values outside that range return null. Check for null before calling.

ParameterType
valuefloat

Returns float?

math.atan

Flowscope Script
math.atan(value: float) -> float

Returns the arctangent of a number in radians.

The result is between -math.pi / 2.0 and math.pi / 2.0.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.atan2

Flowscope Script
math.atan2(y: float, x: float) -> float

Returns the angle of a vector in radians.

y and x are the vector’s coordinates. The result is from -math.pi to math.pi, inclusive.

Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
yfloat
xfloat

Returns float

math.cbrt

Flowscope Script
math.cbrt(value: float) -> float

Returns the cube root of a number.

value can be negative, zero, or positive.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.ceil

Flowscope Script
math.ceil(value: float) -> float

Rounds a number up to a whole number.

For example, 1.2 becomes 2.0 and -1.8 becomes -1.0.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.ceilTo

Flowscope Script
math.ceilTo(value: float, step: float) -> float?

Rounds a float up to a multiple of step.

value is divided by step, rounded up, and multiplied by step. A zero, null, or NaN step returns null instead of stopping the script with an error. Check for null before calling.

ParameterType
valuefloat
stepfloat

Returns float?

math.clamp

Flowscope Script
math.clamp(value: number, min: number, max: number) -> same_numeric

Keeps a number within a range.

Returns value when it is between min and max, including both ends. Below the range it returns min; above the range it returns max.

Mixing ints and floats gives a float result. min > max stops the script with an error. Check for null or use ?? to supply a fallback before calling.

ParameterType
valuenumber
minnumber
maxnumber

Returns same_numeric

math.cos

Flowscope Script
math.cos(value: float) -> float

Returns the cosine of an angle in radians.

value is the angle in radians.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.cosh

Flowscope Script
math.cosh(value: float) -> float

Returns the hyperbolic cosine of a number.

value is the number to calculate from.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.exp

Flowscope Script
math.exp(value: float) -> float

Returns e raised to a power.

value is the exponent. A result too large for a float may be infinite.

Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.floor

Flowscope Script
math.floor(value: float) -> float

Rounds a number down to a whole number.

For example, 1.8 becomes 1.0 and -1.2 becomes -2.0.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.floorTo

Flowscope Script
math.floorTo(value: float, step: float) -> float?

Rounds a float down to a multiple of step.

value is divided by step, rounded down, and multiplied by step. A zero, null, or NaN step returns null instead of stopping the script with an error. Check for null before calling.

ParameterType
valuefloat
stepfloat

Returns float?

math.isEven

Flowscope Script
math.isEven(value: int) -> bool

Tests whether an integer is even.

Returns true when value % 2 == 0. Check for null before using a nullable int. Supported integers range from math.minInt (-9223372036854775807) to math.maxInt (9223372036854775807).

ParameterType
valueint

Returns bool

math.isFinite

Flowscope Script
math.isFinite(value: float?) -> bool

Reports whether a number is finite and non-null.

Returns false for null, NaN, and positive or negative infinity; otherwise true.

This check does not change a nullable value’s type. Use x != null when you need to use x as a non-null value.

ParameterType
valuefloat?

Returns bool

math.isOdd

Flowscope Script
math.isOdd(value: int) -> bool

Tests whether an integer is odd.

Returns true when value % 2 != 0. Check for null before using a nullable int. Supported integers range from math.minInt (-9223372036854775807) to math.maxInt (9223372036854775807).

ParameterType
valueint

Returns bool

math.log

Flowscope Script
math.log(value: float) -> float?

Returns the natural logarithm of a float.

value must be greater than 0.0 for a real result. Values at or below 0.0 return null. Check for null before calling.

ParameterType
valuefloat

Returns float?

math.log10

Flowscope Script
math.log10(value: float) -> float?

Returns the base-10 logarithm of a float.

value must be greater than 0.0 for a real result. Values at or below 0.0 return null. Check for null before calling.

ParameterType
valuefloat

Returns float?

math.log2

Flowscope Script
math.log2(value: float) -> float?

Returns the base-2 logarithm of a float.

value must be greater than 0.0 for a real result. Values at or below 0.0 return null. Check for null before calling.

ParameterType
valuefloat

Returns float?

math.max

Flowscope Script
math.max(value: number, values: number...) -> same_numeric

Returns the largest of one or more numbers.

Pass the first number as value and any others as values. Mixing ints and floats gives a float result.

Check for null or use ?? to supply a fallback before calling. NaN inputs produce null.

ParameterType
valuenumber
valuesnumber

Returns same_numeric

math.min

Flowscope Script
math.min(value: number, values: number...) -> same_numeric

Returns the smallest of one or more numbers.

Pass the first number as value and any others as values. Mixing ints and floats gives a float result.

Check for null or use ?? to supply a fallback before calling. NaN inputs produce null.

ParameterType
valuenumber
valuesnumber

Returns same_numeric

math.pow

Flowscope Script
math.pow(base: float, exponent: float) -> float?

Raises a number to a power.

Returns base raised to exponent, as a float. Inputs with no real-number result, such as a negative base with a fractional exponent, return null.

Check for null or use ?? to supply a fallback before calling.

ParameterType
basefloat
exponentfloat

Returns float?

math.randomFloat

Flowscope Script
math.randomFloat(min: float, max: float) -> float

Returns a random float from min up to, but not including, max.

Both bounds are required. Every equal-sized part of the range is equally likely. min >= max stops the script with an error.

Call this inside a handler. Replaying the same script uses the same sequence of random values.

ParameterType
minfloat
maxfloat

Returns float

Available in Handlers and functions called from handlers.

math.randomInt

Flowscope Script
math.randomInt(min: int, max: int) -> int

Returns a random whole number between min and max, including both.

Both bounds are required. Every integer in the range is equally likely. min > max stops the script with an error. Bounds must be within math.minInt (-9223372036854775807) and math.maxInt (9223372036854775807).

Replaying the same script uses the same sequence of random values.

ParameterType
minint
maxint

Returns int

Available in Handlers and functions called from handlers.

math.round

Flowscope Script
math.round(value: number, decimals: int = 0) -> float

Rounds a number to a chosen number of decimal places.

value can be an int or float; the result is always a float. decimals defaults to 0, which rounds to a whole number. Negative decimals round to tens, hundreds, and so on.

Check for null or use ?? to supply a fallback before calling. NaN inputs return null.

ParameterType
valuenumber
decimalsint

Returns float

math.roundTo

Flowscope Script
math.roundTo(value: float, step: float) -> float?

Rounds a float to the nearest multiple of step.

value is divided by step, rounded to the nearest integer value, and multiplied by step. A zero, null, or NaN step returns null instead of stopping the script with an error. Check for null before calling.

ParameterType
valuefloat
stepfloat

Returns float?

math.safeDiv

Flowscope Script
math.safeDiv(num: float?, den: float?, fallback: float = 0) -> float?

Returns a division result with a fallback for zero or missing denominators.

num is the numerator. den is the denominator; zero or null den returns fallback. Null num returns null because the numerator is missing. Otherwise the result is num / den.

ParameterType
numfloat?
denfloat?
fallbackfloat

Returns float?

math.sign

Flowscope Script
math.sign(value: float) -> float

Returns -1.0, 0.0, or 1.0 for a number’s sign.

Returns -1.0 for negative values, 1.0 for positive values, and 0.0 for both 0.0 and -0.0.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.sin

Flowscope Script
math.sin(value: float) -> float

Returns the sine of an angle in radians.

value is the angle in radians.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.sinh

Flowscope Script
math.sinh(value: float) -> float

Returns the hyperbolic sine of a number.

value is the number to calculate from.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.sqrt

Flowscope Script
math.sqrt(value: float) -> float?

Returns the square root of a float.

value must be non-negative for a real result. Negative values produce null. Check for null before calling.

ParameterType
valuefloat

Returns float?

math.tan

Flowscope Script
math.tan(value: float) -> float

Returns the tangent of an angle in radians.

value is the angle in radians. Near odd multiples of math.pi / 2.0, the result may be very large or infinite.

Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.tanh

Flowscope Script
math.tanh(value: float) -> float

Returns the hyperbolic tangent of a number.

Returns a value from -1.0 to 1.0.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

math.trunc

Flowscope Script
math.trunc(value: float) -> float

Removes the fractional part of a number.

Rounds toward zero: 1.8 becomes 1.0 and -1.8 becomes -1.0.

The result is a float. Check for null or use ?? to supply a fallback before calling. Null or NaN inputs return null.

ParameterType
valuefloat

Returns float

Constants

ConstantTypeValueDescription
math.efloat2.718281828459045Euler’s number, the base of natural logarithms.
math.epsilonfloat2.220446049250313e-16The gap between 1.0 and the next larger float.
math.maxFloatfloat1.7976931348623157e+308The largest finite float.
math.maxIntint9223372036854775807The largest supported integer.
math.minFloatfloat-1.7976931348623157e+308The most negative finite float.
math.minIntint-9223372036854775807Lowest supported integer value (-9223372036854775807).
math.pifloat3.141592653589793Pi, the ratio of a circle’s circumference to its diameter.
math.taufloat6.283185307179586Tau, equal to 2.0 * math.pi.