mathライブラリ
ライブラリ日本語解説あり
ひとことで言うと
計算のためのライブラリです。ランダムな数・切り捨て・最大最小・角度の変換などが使えます。
公式の説明(英語):A library of math functions.
使用例
Script置く場所:パーツの中
local part = script.Parent :: BasePart
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
clickDetector.MouseClick:Connect(function()
part.Color = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))
end)スクリプトは、Luauの型チェック(luau-lsp)で確認しています。
プロパティ(7)
| 名前と書き方 | 説明 |
|---|---|
emath.e: number | The value of Euler's number, e. |
hugemath.huge: number | Returns a value larger than or equal to any other numerical value (about 2<sup>1024</sup>). |
nanmath.nan: number | A NaN value, as defined by the IEEE 754 standard. |
phimath.phi: number | The value of the golden ratio. |
pimath.pi: number | 円周率。The value of pi. |
sqrt2math.sqrt2: number | The value of the square root of 2. |
taumath.tau: number | The value of tau, which is defined as 2 * math.pi. |
関数(37)
| 名前と書き方 | 説明 |
|---|---|
absmath.abs(x: number): number | 絶対値を返します。Returns the absolute value of x. |
acosmath.acos(x: number): number | Returns the arc cosine of x. |
asinmath.asin(x: number): number | Returns the arc sine of x. |
atanmath.atan(x: number): number | Returns the arc tangent of x in radians. |
atan2math.atan2(y: number, x: number): number | Returns the arc tangent of y/x (in radians) while using the signs of both parameters to find the quadrant of the result. |
ceilmath.ceil(x: number): int | 小数点以下を切り上げます。Returns the smallest integer larger than or equal to x. |
clampmath.clamp(x: number, min: number, max: number): number | 値を指定した範囲におさめます。Returns a number between min and max, inclusive. |
cosmath.cos(x: number): number | Returns the cosine of x, assumed to be in radians. |
coshmath.cosh(x: number): number | Returns the hyperbolic cosine of x. |
degmath.deg(x: number): number | Returns the angle x (given in radians) in degrees. |
expmath.exp(x: number): number | Returns the value e^x. |
floormath.floor(x: number): int | 小数点以下を切り捨てます。Returns the largest integer smaller than or equal to x. |
fmodmath.fmod(x: number, y: number): number | Returns the remainder of the division of x by y that rounds the quotient towards zero. |
frexpmath.frexp(x: number): number, int | Returns m and e such that x = m\*2^e. |
isfinitemath.isfinite(x: number): boolean | Returns true if x is a finite number. |
isinfmath.isinf(x: number): boolean | Returns true if x is positive or negative infinity and false otherwise. |
isnanmath.isnan(x: number): boolean | Returns true if x is not a number (NaN) and false otherwise. |
ldexpmath.ldexp(x: number, e: int): number | Returns x\*2^e (e should be an integer). |
lerpmath.lerp(a: number, b: number, t: number): number | Returns the linear interpolation between a and b. |
logmath.log(x: number, base: number): number | Returns the logarithm of x using the given base. |
log10math.log10(x: number): number | Returns the base-10 logarithm of x. |
mapmath.map(x: number, inmin: number, inmax: number, outmin: number, outmax: number): number | Returns the value of x mapped from one range to another. |
maxmath.max(x: number, ...: number): number | いちばん大きい値を返します。Returns the maximum value among the numbers passed to the function. |
minmath.min(x: number, ...: number): number | いちばん小さい値を返します。Returns the minimum value among the numbers passed to the function. |
modfmath.modf(x: number): number, number | Returns two numbers: the integral part of x and the fractional part of x. |
noisemath.noise(x: number, y: number, z: number): number | Returns a Perlin noise value. |
powmath.pow(x: number, y: number): number | Returns x^y. |
radmath.rad(x: number): number | 角度(度)をラジアンに変換します。CFrame.Anglesで使います。Returns the angle x (given in degrees) in radians. |
randommath.random(m: number, n: number): number | ランダムな数を返します。math.random(1, 6) で1〜6の整数。Returns a random number within the range provided. |
randomseedmath.randomseed(x: number): () | Sets x as the seed for the pseudo-random generator. |
roundmath.round(x: number): number | 四捨五入します。Returns the integer with the smallest difference between it and the given number. |
signmath.sign(x: number): int | Returns -1 if x is less than 0, 0 if x equals 0, or 1 if x is greater than 0. |
sinmath.sin(x: number): number | Returns the sine of x, assumed to be in radians. |
sinhmath.sinh(x: number): number | Returns the hyperbolic sine of x. |
sqrtmath.sqrt(x: number): number | 平方根。Returns the square root of x. |
tanmath.tan(x: number): number | Returns the tangent of x, assumed to be in radians. |
tanhmath.tanh(x: number): number | Returns the hyperbolic tangent of x. |
mathを使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(math)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。