p-math
math モジュールはJavaScriptの Math メソッドすべてと、小文字の定数エイリアスを提供します。
use p-math as m| 名前 | 値 | 説明 |
|---|---|---|
pi | 3.141592653589793 | 円周率 |
e | 2.718281828459045 | オイラー数 |
ln2 | 0.6931471805599453 | 2の自然対数 |
ln10 | 2.302585092994046 | 10の自然対数 |
log2e | 1.4426950408889634 | eの底2の対数 |
log10e | 0.4342944819032518 | eの底10の対数 |
sqrt2 | 1.4142135623730951 | 2の平方根 |
sqrt1_2 | 0.7071067811865476 | 1/2の平方根 |
use p-math as mconsole.log[m.pi] -- 3.141592653589793console.log[m.e] -- 2.718281828459045floor[x]
Section titled “floor[x]”x 以下の最大の整数を返します。
ceil[x]
Section titled “ceil[x]”x 以上の最小の整数を返します。
round[x]
Section titled “round[x]”x を最も近い整数に丸めて返します。
trunc[x]
Section titled “trunc[x]”x の小数部分を除去した整数部分を返します。
use p-math as mm.floor[4.7] -- 4m.ceil[4.1] -- 5m.round[4.5] -- 5m.trunc[4.9] -- 4abs[x]
Section titled “abs[x]”x の絶対値を返します。
sign[x]
Section titled “sign[x]”x の符号を示す -1、0、または 1 を返します。
max[a; b; ...]
Section titled “max[a; b; ...]”与えられた数値の最大値を返します。
min[a; b; ...]
Section titled “min[a; b; ...]”与えられた数値の最小値を返します。
pow[base; exp]
Section titled “pow[base; exp]”base を exp 乗した値を返します。
sqrt[x]
Section titled “sqrt[x]”x の平方根を返します。
cbrt[x]
Section titled “cbrt[x]”x の立方根を返します。
hypot[a; b; ...]
Section titled “hypot[a; b; ...]”引数の二乗の和の平方根を返します。
clz32[x]
Section titled “clz32[x]”x の32ビット整数表現における先頭のゼロビット数を返します。
fround[x]
Section titled “fround[x]”x の最も近い32ビット単精度浮動小数点数表現を返します。
imul[a; b]
Section titled “imul[a; b]”a と b のC言語風32ビット乗算の結果を返します。
use p-math as mm.abs[-5] -- 5m.max[1; 2; 3] -- 3m.min[1; 2; 3] -- 1m.sqrt[16] -- 4m.hypot[3; 4] -- 5sin[x] / cos[x] / tan[x]
Section titled “sin[x] / cos[x] / tan[x]”標準三角関数。x はラジアン。
asin[x] / acos[x] / atan[x]
Section titled “asin[x] / acos[x] / atan[x]”逆三角関数。ラジアンを返します。
atan2[y; x]
Section titled “atan2[y; x]”正のx軸と点(x, y)との間の角度をラジアンで返します。
sinh[x] / cosh[x] / tanh[x]
Section titled “sinh[x] / cosh[x] / tanh[x]”双曲線関数。
asinh[x] / acosh[x] / atanh[x]
Section titled “asinh[x] / acosh[x] / atanh[x]”逆双曲線関数。
use p-math as mm.sin[m.pi div 2] -- 1m.cos[0] -- 1m.atan2[1; 1] -- 0.7853... (π/4)log[x]
Section titled “log[x]”x の自然対数(底 e)を返します。
log2[x]
Section titled “log2[x]”x の底2の対数を返します。
log10[x]
Section titled “log10[x]”x の底10の対数を返します。
exp[x]
Section titled “exp[x]”e の x 乗を返します。
expm1[x]
Section titled “expm1[x]”e^x - 1 を返します。x が小さい場合に正確です。
log1p[x]
Section titled “log1p[x]”1 + x の自然対数を返します。x が小さい場合に正確です。
use p-math as mm.log[m.e] -- 1m.log2[8] -- 3m.log10[1000] -- 3m.exp[1] -- 2.718281828459045random[]
Section titled “random[]”[0, 1) の範囲の浮動小数点数を返します。その他のランダムユーティリティは random モジュールを参照してください。
use p-math as mconst x be m.random[] -- 例: 0.4231...