.. _lua-funcs-math: Mathematical Functions ======================= Original document, see: http://www.lua.org/manual/5.1/manual.html This library is an interface to the standard C-math library. It provides all its functions inside the table ``math``. .. index:: math.abs (Lua) .. _lua-func-math.abs: math.abs -------------- .. function:: math.abs (x) Returns the absolute value of ``x``. .. index:: math.acos (Lua) .. _lua-func-math.acos: math.acos -------------- .. function:: math.acos (x) Returns the arc cosine of ``x`` (in radians). .. index:: math.asin (Lua) .. _lua-func-math.asin: math.asin -------------- .. function:: math.asin (x) Returns the arc sine of ``x`` (in radians). .. index:: math.atan (Lua) .. _lua-func-math.atan: math.atan -------------- .. function:: math.atan (x) Returns the arc tangent of ``x`` (in radians). .. index:: math.atan2 (Lua) .. _lua-func-math.atan2: math.atan2 -------------- .. function:: math.atan2 (y, x) Returns the arc tangent of ``y/x`` (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of ``x`` being zero.) .. index:: math.ceil (Lua) .. _lua-func-math.ceil: math.ceil -------------- .. function:: math.ceil (x) Returns the smallest integer larger than or equal to ``x``. .. index:: math.cos (Lua) .. _lua-func-math.cos: math.cos -------------- .. function:: math.cos (x) Returns the cosine of ``x`` (assumed to be in radians). .. index:: math.cosh (Lua) .. _lua-func-math.cosh: math.cosh -------------- .. function:: math.cosh (x) Returns the hyperbolic cosine of ``x``. .. index:: math.deg (Lua) .. _lua-func-math.deg: math.deg -------------- .. function:: math.deg (x) Returns the angle ``x`` (given in radians) in degrees. .. index:: math.exp (Lua) .. _lua-func-math.exp: math.exp -------------- .. function:: math.exp (x) Returns the value *ex*. .. index:: math.floor (Lua) .. _lua-func-math.floor: math.floor -------------- .. function:: math.floor (x) Returns the largest integer smaller than or equal to ``x``. .. index:: math.fmod (Lua) .. _lua-func-math.fmod: math.fmod -------------- .. function:: math.fmod (x, y) Returns the remainder of the division of ``x`` by ``y`` that rounds the quotient towards zero. .. index:: math.frexp (Lua) .. _lua-func-math.frexp: math.frexp -------------- .. function:: math.frexp (x) Returns ``m`` and ``e`` such that *x = m2^e*, ``e`` is an integer and the absolute value of ``m`` is in the range *[0.5, 1)* (or zero when ``x`` is zero). .. index:: math.huge (Lua) .. _lua-func-math.huge: math.huge -------------- .. uparam:: math.huge The value ``HUGE_VAL``, a value larger than or equal to any other numerical value. .. index:: math.log (Lua) .. _lua-func-math.ldexp: math.ldexp -------------- .. function:: math.ldexp (m, e) Returns *m2^e* (``e`` should be an integer). .. index:: math.log (Lua) .. _lua-func-math.log: math.log -------------- .. function:: math.log (x) Returns the natural logarithm of ``x``. .. index:: math.log10 (Lua) .. _lua-func-math.log10: math.log10 -------------- .. function:: math.log10 (x) Returns the base-10 logarithm of ``x``. .. index:: math.max (Lua) .. _lua-func-math.max: math.max -------------- .. function:: math.max (x, ...) Returns the maximum value among its arguments. .. index:: math.min (Lua) .. _lua-func-math.min: math.min -------------- .. function:: math.min (x, ...) Returns the minimum value among its arguments. .. index:: math.modf (Lua) .. _lua-func-math.modf: math.modf -------------- .. function:: math.modf (x) Returns two numbers, the integral part of ``x`` and the fractional part of ``x``. .. index:: math.pi (Lua) .. _lua-func-math.pi: math.pi -------------- .. uparam:: math.pi The value of *pi*. .. index:: math.pow (Lua) .. _lua-func-math.pow: math.pow -------------- .. function:: math.pow (x, y) Returns *x^y*. (You can also use the expression ``x^y`` to compute this value.) .. index:: math.rad (Lua) .. _lua-func-math.rad: math.rad -------------- .. function:: math.rad (x) Returns the angle ``x`` (given in degrees) in radians. .. index:: math.random (Lua) .. _lua-func-math.random: math.random -------------- .. function:: math.random ([m [, n]]) This function is an interface to the simple pseudo-random generator function ``rand`` provided by ANSI-C. (No guarantees can be given for its statistical properties.) When called without arguments, returns a uniform pseudo-random real number in the range *[0,1)*. When called with an integer number ``m``, ``math.random`` returns a uniform pseudo-random integer in the range *[1, m]*. When called with two integer numbers ``m`` and ``n``, ``math.random`` returns a uniform pseudo-random integer in the range *[m, n]*. .. index:: math.randomseed (Lua) .. _lua-func-math.randomseed: math.randomseed ---------------- .. function:: math.randomseed (x) Sets ``x`` as the "seed" for the pseudo-random generator: equal seeds produce equal sequences of numbers. .. index:: math.sin (Lua) .. _lua-func-math.sin: math.sin -------------- .. function:: math.sin (x) Returns the sine of ``x`` (assumed to be in radians). .. index:: math.sinh (Lua) .. _lua-func-math.sinh: math.sinh -------------- .. function:: math.sinh (x) Returns the hyperbolic sine of ``x``. .. index:: math.sqrt (Lua) .. _lua-func-math.sqrt: math.sqrt -------------- .. function:: math.sqrt (x) Returns the square root of ``x``. (You can also use the expression ``x^0.5`` to compute this value.) .. index:: math.tan (Lua) .. _lua-func-math.tan: math.tan -------------- .. function:: math.tan (x) Returns the tangent of ``x`` (assumed to be in radians). .. index:: math.tanh (Lua) .. _lua-func-math.tanh: math.tanh -------------- .. function:: math.tanh (x) Returns the hyperbolic tangent of ``x``. :sub:`id-2099528`