| Lua math functions |
|---|
| Lua math functions These are the functions in the "math" table. Trigonometry functions use radians. To convert degrees to radians use math.rad. Or, to look at it another way: math.abs (v) Absolute value of v. math.acos (v) Arc cosine of v. (Inverse operation of math.cos (v)). math.asin (v) Arc sine of v. (Inverse operation of math.sin(v)). math.atan (v) Arc tangent of v. (Inverse operation of math.tan (v)). math.atan2 (v1, v2) Arc tangent of v1/v2. math.ceil (v) Smallest integer >= v math.cos (v) Cosine of v radians. math.cosh (v) Hyperbolic cosine of v radians. math.deg (v) Convert v from radians to degrees. Note that math.rad is the inverse operation. math.exp (v) e to the power v. Note that math.log is the inverse operation. math.floor () Largest integer <= v math.fmod (v1, v2) The modulus (remainder) of doing: v1 / v2 m, n = math.frexp (v) The frexp function breaks down the floating-point value (v) into a mantissa (m) and an exponent (n), such that the absolute value of m is greater than or equal to 0.5 and less than 1.0, and v = m * 2^n. Note that math.ldexp is the inverse operation. math.huge The value HUGE_VAL, a value larger than or equal to any other numerical value. Note that this is a number, not a function. math.ldexp (m, n) The ldexp function returns the value of m * 2^b. Note that math.frexp is the inverse operation. math.log (v) Natural log of v. Note that math.exp is the inverse operation. math.log10 (v) Log to the base 10 of v. math.max (v1, v2, ...) The highest of one or more numbers. math.min () The lowest of one or more numbers. i, f = math.modf (v) Returns two numbers, the integral part of v and the fractional part of v math.pi A variable representing the value of pi (not a function). math.pow (v1, v2) v1 raised to the power v2. math.rad (v) Convert v from degrees to radians. Note that math.deg is the inverse operation. math.random (n, u) With no arguments, returns a random number in the range [0, 1). That is, zero up to but excluding 1. With 1 argument, returns an integer in the range [1, n]. That is from 1 up to and including n. With 2 arguments, returns an integer in the range [n, u]. That is from n up to and including u. Use math.randomseed to seed the generator. math.randomseed () Seeds the random number generator with an integer. Re-seed with the same number to regenerate the same sequences by calling math.random. math.sin (v) Sine of v radians. math.sinh (v) Hyperbolic sine of v radians. math.sqrt () Square root of v. math.tan (v) Tangent of v radians. math.tanh (v) Hyperbolic tangent of v radians. See Also ... Topics
Lua base functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua os functions
Lua package functions
Lua script extensions
Lua string functions
Lua table functions(Help topic: general=lua_math)
Documentation contents page |