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)

名前と書き方説明
e
math.e: number
The value of Euler's number, e.
huge
math.huge: number
Returns a value larger than or equal to any other numerical value (about 2<sup>1024</sup>).
nan
math.nan: number
A NaN value, as defined by the IEEE 754 standard.
phi
math.phi: number
The value of the golden ratio.
pi
math.pi: number
円周率。The value of pi.
sqrt2
math.sqrt2: number
The value of the square root of 2.
tau
math.tau: number
The value of tau, which is defined as 2 * math.pi.

関数(37)

名前と書き方説明
abs
math.abs(x: number): number
絶対値を返します。Returns the absolute value of x.
acos
math.acos(x: number): number
Returns the arc cosine of x.
asin
math.asin(x: number): number
Returns the arc sine of x.
atan
math.atan(x: number): number
Returns the arc tangent of x in radians.
atan2
math.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.
ceil
math.ceil(x: number): int
小数点以下を切り上げます。Returns the smallest integer larger than or equal to x.
clamp
math.clamp(x: number, min: number, max: number): number
値を指定した範囲におさめます。Returns a number between min and max, inclusive.
cos
math.cos(x: number): number
Returns the cosine of x, assumed to be in radians.
cosh
math.cosh(x: number): number
Returns the hyperbolic cosine of x.
deg
math.deg(x: number): number
Returns the angle x (given in radians) in degrees.
exp
math.exp(x: number): number
Returns the value e^x.
floor
math.floor(x: number): int
小数点以下を切り捨てます。Returns the largest integer smaller than or equal to x.
fmod
math.fmod(x: number, y: number): number
Returns the remainder of the division of x by y that rounds the quotient towards zero.
frexp
math.frexp(x: number): number, int
Returns m and e such that x = m\*2^e.
isfinite
math.isfinite(x: number): boolean
Returns true if x is a finite number.
isinf
math.isinf(x: number): boolean
Returns true if x is positive or negative infinity and false otherwise.
isnan
math.isnan(x: number): boolean
Returns true if x is not a number (NaN) and false otherwise.
ldexp
math.ldexp(x: number, e: int): number
Returns x\*2^e (e should be an integer).
lerp
math.lerp(a: number, b: number, t: number): number
Returns the linear interpolation between a and b.
log
math.log(x: number, base: number): number
Returns the logarithm of x using the given base.
log10
math.log10(x: number): number
Returns the base-10 logarithm of x.
map
math.map(x: number, inmin: number, inmax: number, outmin: number, outmax: number): number
Returns the value of x mapped from one range to another.
max
math.max(x: number, ...: number): number
いちばん大きい値を返します。Returns the maximum value among the numbers passed to the function.
min
math.min(x: number, ...: number): number
いちばん小さい値を返します。Returns the minimum value among the numbers passed to the function.
modf
math.modf(x: number): number, number
Returns two numbers: the integral part of x and the fractional part of x.
noise
math.noise(x: number, y: number, z: number): number
Returns a Perlin noise value.
pow
math.pow(x: number, y: number): number
Returns x^y.
rad
math.rad(x: number): number
角度(度)をラジアンに変換します。CFrame.Anglesで使います。Returns the angle x (given in degrees) in radians.
random
math.random(m: number, n: number): number
ランダムな数を返します。math.random(1, 6) で1〜6の整数。Returns a random number within the range provided.
randomseed
math.randomseed(x: number): ()
Sets x as the seed for the pseudo-random generator.
round
math.round(x: number): number
四捨五入します。Returns the integer with the smallest difference between it and the given number.
sign
math.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.
sin
math.sin(x: number): number
Returns the sine of x, assumed to be in radians.
sinh
math.sinh(x: number): number
Returns the hyperbolic sine of x.
sqrt
math.sqrt(x: number): number
平方根。Returns the square root of x.
tan
math.tan(x: number): number
Returns the tangent of x, assumed to be in radians.
tanh
math.tanh(x: number): number
Returns the hyperbolic tangent of x.

mathを使う記事

英語の説明とメンバーの一覧は、Roblox Creator Documentation(math)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。

執筆:鈴木孝昌官公庁のWeb・システム開発を担当する現役プロジェクトマネージャー。沖縄マイクラ部 クロスウェーブで、ロブロックス(Roblox)・マインクラフト(マイクラ)・Scratchなどのプログラミングを指導。マイクラカップ沖縄代表チームを指導(第6回・第7回、第7回TBS賞)。
沖縄マイクラ部で、子どもたちにロブロックス(Roblox)やマインクラフト(マイクラ)のプログラミングを教えています。プロフィールと編集方針
Instagramで教室の様子を見る
noteで記事を読む