Function Dump/Mathematical Functions: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
mNo edit summary
>Mindraker
No edit summary
Line 75: Line 75:


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 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.)
{{Example|
<pre>
a=math.atan2 (1,2)
b=math.deg (a)
print(b)
Will result in:
26.565051177078 (degrees)
</pre>
}}




Line 100: Line 111:
{{Example|
{{Example|
<pre>
<pre>
print(math.cos (1))
a=math.cos (1)
print(a)


Will result in:
Will result in:
Line 114: Line 126:
{{Example|
{{Example|
<pre>
<pre>
print(math.cosh (1))
a=math.cosh (1)
print(a)


Will result in:
Will result in:
Line 128: Line 141:
{{Example|
{{Example|
<pre>
<pre>
print(math.deg (1.5707963267948966192313216916398))
a=math.deg (1.5707963267948966192313216916398)
print(a)


Will result in:
Will result in:
Line 303: Line 317:
{{Example|
{{Example|
<pre>
<pre>
print(math.pi)
a=(math.pi^2)
print(math.sqrt(a))


Will result in:
Will result in:

Revision as of 16:19, 14 October 2008


Mathematical Functions

This library is an interface to the standard C math library. It provides all its functions inside the table math.


math.abs (x)


Returns the absolute value of x.

Example
a=math.abs(-5)
print(10 + a)

Will result in:
15


math.acos (x)


Returns the arc cosine of x (in radians).

Example
a=math.acos (0.5) 
b=math.deg (a)
print(b)

Will result in:
60 (degrees)


math.asin (x)


Returns the arc sine of x (in radians).

Example
a=math.asin (0.5)
b=math.deg (a)
print(b)

Will result in:
30 (degrees)


math.atan (x)


Returns the arc tangent of x (in radians).

Example
a=math.atan (0.5)
b=math.deg (a)
print(b)

Will result in:
26.565051177078 (degrees)


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.)

Example
a=math.atan2 (1,2)
b=math.deg (a)
print(b)

Will result in:
26.565051177078 (degrees)


math.ceil (x)


Returns the smallest integer larger than or equal to x.

Example
z=math.ceil (4.2)
print(z)

Will result in:
5


math.cos (x)


Returns the cosine of x (assumed to be in radians).

Example
a=math.cos (1)
print(a)

Will result in:
0.54030230586814


math.cosh (x)


Returns the hyperbolic cosine of x.

Example
a=math.cosh (1)
print(a)

Will result in:
1.5430806348152


'math.deg (x)


Returns the angle x (given in radians) in degrees.

Example
a=math.deg (1.5707963267948966192313216916398)
print(a)

Will result in:
90


math.exp (x)


Returns the the value e^x.

Example
print(math.exp (1))

Will result in:
2.718281828459


math.floor (x)


Returns the largest integer smaller than or equal to x.

Example
z=math.ceil (4.2)
print(z)

Will result in:
4


math.fmod (x, y)


Returns the remainder of the division of x by y that rounds the quotient towards zero.

Example
print(math.fmod (10, 3))

Will result in:
1


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).

Example
print(math.frexp (0))

Will result in:
0 0
print(math.frexp (4))

Will result in:
0.5 3 -- (2^3/2=4)


math.huge


The value HUGE_VAL, a value larger than or equal to any other numerical value.

Example
print(math.huge)

Will result in:
1.#INF


math.ldexp (m, e)


Returns m*2^e (e should be an integer).

Example
print(math.ldexp (2, 6))

Will result in:
128 (i.e., (2*(2^6))


math.log (x)


Returns the natural logarithm of x.

Example
print(math.log (2.71828182845904523536))

Will result in:
1


math.log10 (x)


Returns the base-10 logarithm of x.

Example
print(math.log10 (100))

Will result in:
2


math.max (x, ···)


Returns the maximum value among its arguments.

Example
print(math.max (1, 2, 3, 4, 5, 6, 7))
Will result in:
7


math.min (x, ···)


Returns the minimum value among its arguments.

Example
print(math.min (1, 2, 3, 4, 5, 6, 7))

Will result in:
1


math.modf (x)


Returns two numbers, the integral part of x and the fractional part of x.

Example
print(math.modf (2.5))

Will result in:
2 0.5


math.pi


The value of pi.

Example
a=(math.pi^2)
print(math.sqrt(a))

Will result in:
3.1415926535898


math.pow (x, y)


Returns x^y. (You can also use the expression x^y to compute this value.)

Example
print(math.pow (4, 2))

Will result in:
16


math.rad (x)


Returns the angle x (given in degrees) in radians.

Example
print(math.rad (90))

Will result in:
1.5707963267949 (Which is pi/2)


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 pseudo-random real number in the range [0,1). When called with a number m, math.random returns a pseudo-random integer in the range [1, m]. When called with two numbers m and n, math.random returns a pseudo-random integer in the range [m, n].

Example
print(math.random (0, 10))

Might result in:
7


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).

Example
print(math.sin (1.5707963267948966192313216916398))

Will result in:
1


math.sinh (x)


Returns the hyperbolic sine of x.

Example
print(math.sinh (0))

Will result in:
0


math.sqrt (x)


Returns the square root of x. (You can also use the expression x^0.5 to compute this value.)

Example
z=math.sqrt (16)
print(z)

Will result in:
4


math.tan (x)


Returns the tangent of x (assumed to be in radians).

Example
print(math.tan (1))

Will result in:
1.5574077246549


math.tanh (x)


Returns the hyperbolic tangent of x.

Example
print(math.tanh (1))

Will result in:
0.76159415595576