Function Dump/Mathematical Functions: Difference between revisions
>JulienDethurens Undo revision 53549 by JulienDethurens (talk) nvm |
>NecroBumpist Complete request on the ROBLOX Wiki Group wall to clear up the synonyms "arc" and "inverse" trigonometric functions. |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 11: | Line 11: | ||
==math.acos(x)== | ==math.acos(x)== | ||
Returns the arc cosine of x (in radians). | Returns the arc[[#Trigonometric Names|*]] cosine of x (in radians). | ||
{{code and output|code= | {{code and output|code= | ||
Line 18: | Line 18: | ||
==math.asin(x)== | ==math.asin(x)== | ||
Returns the arc sine of x (in radians). | Returns the arc[[#Trigonometric Names|*]] sine of x (in radians). | ||
{{code and output|code= | {{code and output|code= | ||
Line 25: | Line 25: | ||
==math.atan(x)== | ==math.atan(x)== | ||
Returns the arc tangent of x (in radians). | Returns the arc[[#Trigonometric Names|*]] tangent of x (in radians). | ||
{{code and output|code= | {{code and output|code= | ||
Line 33: | Line 33: | ||
==math.atan2(y, x)== | ==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. | Returns the arc[[#Trigonometric Names|*]] 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. | ||
==math.ceil(x)== | ==math.ceil(x)== | ||
Returns | Returns a number rounded up (towards positive infinity) to the nearest integer. | ||
{{code and output|code= | {{code and output|code= | ||
print( math.ceil(4.2) ) | print( math.ceil(4.2) ) | ||
|output=5}} | |output=5}} | ||
{{code and output|code= | |||
print( math.ceil(-4.2) ) | |||
|output=-4}} | |||
See also: [[#math.floor(x)|math.floor]]. | |||
==math.cos(x)== | ==math.cos(x)== | ||
Line 71: | Line 76: | ||
==math.floor(x)== | ==math.floor(x)== | ||
Returns the | Returns a number rounded down (towards negative infinity) to the nearest integer. | ||
{{code and output|code= | {{code and output|code= | ||
print( math.floor(4.8) ) | print( math.floor(4.8) ) | ||
|output=4 | |output=4 | ||
}} | |||
{{code and output|code= | |||
print( math.floor(-4.8) ) | |||
|output=-5 | |||
}} | }} | ||
See also: [[#math.ceil(x)|math.ceil]]. | |||
==math.fmod(x, y)== | ==math.fmod(x, y)== | ||
Line 237: | Line 248: | ||
print( math.tanh(1) ) | print( math.tanh(1) ) | ||
|output=0.76159415595576}} | |output=0.76159415595576}} | ||
== Trigonometric Names == | |||
The inverse trigonometric functions (i.e. [[#math.acos(x)|math.acos()]], [[#math.asin(x)|math.asin()]], [[#math.atan(x)|math.atan()]], and [[#math.atan2(y, x)|math.atan2()]]) can be referred to as the "arc" or "inverse" version of their corresponding original function. | |||
This means if someone says "inverse cosine", they are referring to the [[#math.acos(x)|arc cosine]] function, and vice-versa. |
Latest revision as of 15:23, 14 April 2012
This library is an interface to the standard C math library. It provides all its functions inside the table math. The functions are listed below.
math.abs(x)
Returns the absolute value of x.
math.acos(x)
Returns the arc* cosine of x (in radians).
math.asin(x)
Returns the arc* sine of x (in radians).
math.atan(x)
Returns the arc* tangent of x (in radians).
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.
math.ceil(x)
Returns a number rounded up (towards positive infinity) to the nearest integer.
See also: math.floor.
math.cos(x)
Returns the cosine of x (assumed to be in radians).
math.cosh(x)
Returns the hyperbolic cosine of x.
math.deg(x)
Returns the angle x (given in radians) in degrees.
math.exp(x)
Returns the the value e^x.
math.floor(x)
Returns a number rounded down (towards negative infinity) to the nearest integer.
See also: math.ceil.
math.fmod(x, y)
Returns the remainder of the division of x by y that rounds the quotient towards zero.
math.frexp(x)
Returns m and e such that x = m*2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero).
math.huge
A representation of infinity, a value larger than or equal to any other numerical value.
math.ldexp(m, e)
Returns m*2^e (e should be an integer).
math.log(x)
Returns the natural logarithm of x.
math.log10(x)
Returns the base-10 logarithm of x.
math.max(x, ···)
Returns the maximum value among its arguments.
math.min(x, ···)
Returns the minimum value among its arguments.
math.modf(x)
Returns two numbers, the integral part of x and the fractional part of x.
math.pi
The value of pi. Pi is a mathematics term (not the baked good) that represents a very specific number.
math.pow(x, y)
Returns x^y. (You can also use the expression x^y to compute this value.)
math.rad(x)
Returns the angle x (given in degrees) in radians.
math.random([m [, n]])
This function can be called 3 ways:
math.random(min,max) -- returns an Integer min-max
local str = "" for i = 1, 10 do local num = math.random(33, 126) str = str .. string.char(num) end print(str) -- random string length 10
math.random() -- returns a Number value 0-1
local color = Color3.new(math.random(), math.random(), math.random()) print(color) -- random color3
math.random(max) -- returns an Integer 1-max
local list = Workspace:GetChildren() print( list[math.random(#list)] ) -- random item from list
local a = math.random(5)
The first example returns a random item from list, while the second returns an integer between one and five.
If the second number is less than first (or only number is less than 1), you'll get:
bad argument #n to 'random' (interval is empty)
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.)
math.randomseed(x)
Sets x as the "seed" for the pseudo-random generator: equal seeds produce equal sequences of numbers.
math.sin(x)
Returns the sine of x (assumed to be in radians).
math.sinh(x)
Returns the hyperbolic sine of x.
math.sqrt(x)
Returns the square root of x. You can also use the expression x^0.5 to compute this value, but it is less efficient.
math.tan(x)
Returns the tangent of x (assumed to be in radians).
math.tanh(x)
Returns the hyperbolic tangent of x.
Trigonometric Names
The inverse trigonometric functions (i.e. math.acos(), math.asin(), math.atan(), and math.atan2()) can be referred to as the "arc" or "inverse" version of their corresponding original function.
This means if someone says "inverse cosine", they are referring to the arc cosine function, and vice-versa.