Math
Accessed via math
The math module provides common mathematical functions and constants.
Properties
The mathematical constant π (pi).
The mathematical constant e (Euler's number).
The mathematical constant τ (tau), equal to 2π.
A value equal to the largest number in TruScript that can be represented before infinity. To get the inverse sign (approaching negative infinity), use -math.huge.
Functions
Returns the sine of x (in radians).
Returns the cosine of x (in radians).
Returns the tangent of x (in radians).
Returns the absolute value of x.
Returns x raised to the power of y.
Returns the arcsine of x (in radians).
Returns the arccosine of x (in radians).
Returns the arctangent of x (in radians).
Returns the arctangent of y/x (in radians), using the signs of both arguments to determine the quadrant.
Returns the hyperbolic sine of x.
Returns the hyperbolic cosine of x.
Returns the hyperbolic tangent of x.
Returns the inverse hyperbolic sine of x.
Returns the inverse hyperbolic cosine of x.
Returns the inverse hyperbolic tangent of x.
Returns e raised to the power of x.
Returns the natural logarithm of x.
Returns the base-10 logarithm of x.
Returns the base-2 logarithm of x.
Returns the logarithm of x to the given base.
Returns the square root of x.
Returns the cube root of x.
Returns the largest integer less than or equal to x.
Returns the smallest integer greater than or equal to x.
Returns the value of x rounded to the nearest integer.
Returns the value of x rounded to the specified number of decimal places.
Returns the integer part of x, removing any fractional digits.
Returns the sign of x: -1 if x is negative, 0 if x is zero, and 1 if x is positive.
Returns a if it is greater than b, or b otherwise.
Returns a if it is less than b, or b otherwise.
Returns value clamped to the range [min, max].
Returns the linear interpolation between a and b by t. If t is outside the range [0, 1], the result is extrapolated.
Returns the parameter t that produces the given value when linearly interpolating between a and b. In other words, this solves for t in the equation value = lerp(a, b, t). If value is outside the range [a, b], the result is extrapolated.
Returns the linear interpolation between the angles from and to (in radians) by t, taking the shortest path around the circle.
Returns the angle (in radians) normalized to the range [-π, π].
Returns the shortest signed angular difference (in radians) from one angle to another, in the range [-π, π].
Converts an angle from degrees to radians.
Converts an angle from radians to degrees.
Returns a smooth interpolation between 0 and 1 when x is in the range [edge0, edge1]. The result is 0 when x is less than or equal to edge0, and 1 when x is greater than or equal to edge1. The function uses a cubic Hermite interpolation to ensure smoothness at the edges.
Returns a smooth interpolation between 0 and 1 when x is in the range [edge0, edge1], like smoothstep but with an even smoother curve whose first and second derivatives are both zero at the edges.
Returns the distance between the 2D points (x1, y1) and (x2, y2).
Returns the distance between the 3D points (x1, y1, z1) and (x2, y2, z2).
Returns the length of the 2D vector (x, y).
Returns the length of the 3D vector (x, y, z).
Returns value wrapped to the range [min, max). If value is less than min, it wraps around to the upper end of the range. If value is greater than or equal to max, it wraps around to the lower end of the range.
Returns a value that oscillates between 0 and length as value increases. The function is similar to the wrap function, but it "bounces" back and forth between the two ends of the range instead of wrapping around.
Returns a value that repeats every length as value increases. The function is similar to the wrap function, but it always wraps around to the lower end of the range instead of bouncing back and forth.
Returns the value that is moved from current towards target by the maximum amount of max_delta.
Returns true if a and b are equal to within the given epsilon, and false otherwise. Useful for comparing numbers that may carry floating-point error.
Returns true if value is NaN, and false otherwise.
Returns true if value is positive or negative infinity, and false otherwise.
Returns the fractional (decimal) part of x.