math

顯示已棄用項目

This library is an interface to the standard C math library, providing all of its functions inside the math table.

概要

函式

屬性

  • Returns a value larger than or equal to any other numerical value (about 21024).

  • The value of pi.

函式

Returns the absolute value of x.

參數

返回

acos

Returns the arc cosine of x.

參數

返回

asin

Returns the arc sine of x.

參數

返回

atan

Returns the arc tangent of x in radians.

參數

返回

atan2

Returns the arc tangent of y/x (in radians) while using the signs of both parameters to find the quadrant of the result. It also handles correctly the case of x being zero.

參數

返回

ceil

Returns the smallest integer larger than or equal to x.

參數

返回

clamp

Returns a number between min and max, inclusive.

參數

min: number
max: number

返回

Returns the cosine of x, assumed to be in radians.

參數

返回

cosh

Returns the hyperbolic cosine of x.

參數

返回

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

參數

返回

Returns the value e^x.

參數

返回

floor

Returns the largest integer smaller than or equal to x.

參數

返回

fmod

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

參數

返回

frexp

Returns m and e such that x = m*2^e. e is an integer and the absolute value of m is in the range of 0.5 to 1 (inclusive of 0.5 but exclusive of 1), or zero when x is zero.

參數

ldexp

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

參數

返回

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 starting value.

The ending value.

The interpolation factor, typically between 0 and 1.

返回

The interpolated value between a and b.

Returns the logarithm of x using the given base, or the mathematical constant e if no base is provided (natural logarithm).

參數

base: number

The base of the logarithm, the constant e by default.

預設值:2.7182818

返回

log10

Returns the base-10 logarithm of x.

參數

返回

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 number to be mapped.

inmin: number

The lower bound of the input range.

inmax: number

The upper bound of the input range.

outmin: number

The lower bound of the output range.

outmax: number

The upper bound of the output range.

返回

The value of x mapped to the output range.

Returns the maximum value among the numbers passed to the function.

參數

...: number

返回

Returns the minimum value among the numbers passed to the function.

參數

...: number

返回

modf

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

參數

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.

參數

預設值:0
預設值:0

返回

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

參數

返回

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

參數

返回

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.

參數

預設值:0
預設值:1

返回

randomseed

void

Sets x as the seed for the pseudo-random generator: equal seeds produce equal sequences of numbers.

參數

返回

void

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.

返回

sign

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.

參數

返回

sinh

Returns the hyperbolic sine of x.

參數

返回

sqrt

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

參數

返回

Returns the tangent of x, assumed to be in radians.

參數

返回

tanh

Returns the hyperbolic tangent of x.

參數

返回

屬性

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.

The value of pi.