math
This library is an interface to the standard C math library, providing all of its functions inside the math table.
概要
函式
Returns the absolute value of x.
Returns the arc cosine of x.
Returns the arc sine of x.
Returns the arc tangent of x in radians.
Returns the arc tangent of y/x (in radians) while using the signs of both parameters to find the quadrant of the result.
Returns the smallest integer larger than or equal to x.
Returns a number between min and max, inclusive.
Returns the cosine of x, assumed to be in radians.
Returns the hyperbolic cosine of x.
Returns the angle x (given in radians) in degrees.
Returns the value e^x.
Returns the largest integer smaller than or equal to x.
Returns the remainder of the division of x by y that rounds the quotient towards zero.
Returns m and e such that x = m*2^e.
Returns x*2^e (e should be an integer).
Returns the linear interpolation between a and b.
Returns the logarithm of x using the given base.
Returns the base-10 logarithm of x.
Returns the value of x mapped from one range to another.
Returns the maximum value among the numbers passed to the function.
Returns the minimum value among the numbers passed to the function.
Returns two numbers: the integral part of x and the fractional part of x.
Returns a Perlin noise value.
Returns x^y.
Returns the angle x (given in degrees) in radians.
Returns a random number within the range provided.
Sets x as the seed for the pseudo-random generator.
Returns the integer with the smallest difference between it and the given number.
Returns -1 if x is less than 0, 0 if x equals 0, or 1 if x is greater than 0.
Returns the sine of x, assumed to be in radians.
Returns the hyperbolic sine of x.
Returns the square root of x.
Returns the tangent of x, assumed to be in radians.
Returns the hyperbolic tangent of x.
函式
lerp
Returns the linear interpolation between a and b based on the factor t.
This function uses the formula a+(b-a)*t. t is typically between 0 and 1 but values outside this range are acceptable.
參數
返回
The interpolated value between a and b.
map
Returns a value that represents x mapped linearly from the input range (inmin to inmax) to the output range (outmin to outmax). This is achieved by determining the relative position of x within the input range and applying that ratio to the output range.
參數
返回
The value of x mapped to the output range.
noise
Returns a Perlin noise value. The returned value is most often between the range of -1 to 1 (inclusive) but sometimes may be outside that range; if the interval is critical to you, use math.clamp(noise, -1, 1) on the output.
If you leave arguments out, they will be interpreted as zero, so math.noise(1.158) is equivalent to math.noise(1.158, 0, 0) and math.noise(1.158, 5.723) is equivalent to math.noise(1.158, 5.723, 0).
Note that this function uses a Perlin noise algorithm to assign fixed values to coordinates. For example, math.noise(1.158, 5.723) will always return 0.48397532105446 and math.noise(1.158, 6) will always return 0.15315161645412.
If x, y, and z are all integers, the return value will be 0. For fractional values of x, y, and z, the return value will gradually fluctuate between -0.5 and 0.5. For coordinates that are close to each other, the return values will also be close to each other.
返回
random
When called without arguments, returns a uniform pseudo-random real number in the range of 0 to 1 (inclusive of 0 but exclusive of 1).
When called with an integer number m, returns a uniform pseudo-random integer in the range of 1 to m, inclusive.
When called with two integer numbers m and n, returns a uniform pseudo-random integer in the range of m to n, inclusive.
Internally, this uses a 32-bit PCG (Permuted Congruential Generator) which achieves excellent statistical performance and makes its output hard to predict.
返回
randomseed
Sets x as the seed for the pseudo-random generator: equal seeds produce equal sequences of numbers.
參數
返回
round
Returns the integer with the smallest difference between it and the given number. For example, the value 5.8 returns 6.
For values like 0.5 that are equidistant to two integers, the value with the greater difference between it and zero is chosen. In other words, the function "rounds away from zero" such that 0.5 rounds to 1 and -0.5 rounds to -1.
參數
The value to be rounded.
返回
屬性
huge
Returns a value larger than or equal to any other numerical value (about 21024). Dividing a positive number by zero yields this same value.
pi
The value of pi.