~~NOTOC~~ ====== Lua math library ===== ==== Random number generation ==== ^ Method ^ Description ^ | math.random(x,y)| Returns a pseudorandom number from x to y (y is optional, if there is no y, the value will be generated from 1 to x)| | math.randomseed(x)|Sets x as the seed for the pseudo-random seed number generator.| ==== Constants ==== ^ Method ^ Description ^ | math.pi| Value of [[wp>Pi| Pi]])| | math.huge| equal to Infinite| ==== Other Mathematical Operations ==== ^ Method ^ Description ^ | math.abs(x)| Returns the absolute value of x (negative to positive)| | math.sqrt(x)| Returns the [[wp>Square_root|Square root]] of X| | math.max(x,...)| Returns the maximun value from its arguments eg math.max(99,54,23,15,233) -> 223| | math.min(x,...)|Returns the minimun value from its arguments eg math.max(99,54,23,15,233) -> 15| ==== Rounding and remainder ==== ^ Method ^ Description ^ | math.floor(x)| Returns the largest integer smaller than or equal to x| | math.ceil(x)| Returns the smallest integer larger than or equal to x| | math.modf(x)| Returns the integral part of x and the fractional part of x. eg: math.modf(12.321) returns 12 and 0.321| | math.fmod(x,y)| Returns the remainder of the division of x by y rounding the quotient towards zero. eg: math.fmod(10.5 , 3.2) returns ≈0.099999999999998| ==== Exponential and logarithmic methods ==== ^ Method ^ Description ^ | math.exp(x)| Returns the value e raised to the power of x | | math.log(x)| Returns the natural [[wp>Logarithm| Logarithm]] of x | | math.log10(x)| Returns the [[wp> Common_logarithm | Base 10 logarithm]] of x | | math.pow(x,y)| Returns x to the power of y| ==== Trigonometric Methods ==== ^ Method ^ Description ^ | math.acos(x) | Returns the [[wp>Inverse_trigonometric_functions|Arc cosine]] of X (in [[wp>Radian|Radians]])| | math.asin(x)| Returns the [[wp>Inverse_trigonometric_functions|Arc sine]] of x (in [[wp>Radian|Radians]]).| | math.atan(x)| Returns the [[wp>Inverse_trigonometric_functions|Arc tangent]] of x (in[[wp>Radian|Radians]]).| | math.atan2(y,x) | Returns the [[wp>Inverse_trigonometric_functions|Arc cosine]] of Y/X (in [[wp>Radian|Radians]]) but uses the signs of both y and x to determine the angle's quadrant in the coordinate plane. and also handles the case of x being 0 | | math.cos(x)| Returns the [[wp>Sine_and_cosine|Cosine]] of x (assumed to be in [[wp>Radian|Radians]]).| | math.sin(x)| Returns the [[wp>Sine_and_cosine|Sine]] of x (assumed to be in [[wp>Radian|Radians]]).| | math.tan(x)| Returns the [[wp>Tangent_(trigonometry)|Tangent]] of x (assumed to be in[[wp>Radian|Radians]]).| | math.deg(x)| Returns the angle x (given in radians) to [[wp>Degree_(angle)|Degrees]]| | math.rad(x)| Returns the angle x (given in degrees) in [[wp>Radian|Radians]].|