# Lua MathExtra

Development < Lua Scripting < Lua MathExtra

New in Engine Version 0.95 and up.

math. ( number x, number min, number max )
return: number clamped

Returns x clamped to min and max boundaries.

math. ( number x1, number x2, number x3, ... )
return: number diagonal

Returns the length of the diagonal of an n-dimensional box (or the length of an n-component vector). Rather quick method that does not handle intermediate overflows/underflows nor is made for numerical stability.

math. ( number x )
return: number erf

Returns erf(x).

math. ( number x, number y )
return: number sqrt(x*x+y*y)

Returns the length of hypotenuse of right angle triangle with sides x and y, equivalent to sqrt(x*x + y*y), but has better numerical stability and internally handles intermediate overflows/underflows, but is also slower.

math. ( number x, number y, number a )
return: number (x+(y-x)*a)

Returns linear interpolation between x and y with ratio a (x+(y-x)*a).

math. ( number x, number decimals )
return: number rounded

Returns x rounded to n decimals, if n is omitted or <=0, rounds to nearest integer. Note that Spring's Lua interpreter uses 32-bit floats for all numbers so max. precision is ~7 decimal digits.

math. ( number x )
return: number sign

Returns 0 if x ==0, 1 if x > 0, -1 if x < 0 sgn(x).

math. ( number edge0, number edge1, number x )
return: number smoothstep

Returns smoothstep(edge0, edge1, v).