JavaScript Mathオブジェクト・サンプルコード - ray88’s diary
JavaScript 整数の乱数を発生させる・randomメソッドの応用 - ray88’s diary
■Mathオブジェクトの主なメンバー
※「Math.SQRT2」までが静的プロパティ
分類 | メンバー | 戻り値 | 説明 | V8以降 |
---|---|---|---|---|
静的 プロパティ |
Math.E | - | ネイピア数(オイラー数) | - |
Math.LN2 | - | 2の自然対数 | - | |
Math.LN10 | - | 10の自然対数 | - | |
Math.LOG2E | - | 2を底としたEの対数 | - | |
Math.LOG10E | - | 10を底としたEの対数 | - | |
Math.PI | - | 円周率 | - | |
Math.SQRT1_2 | - | 1/2の平方根 | - | |
Math.SQRT2 | - | 2の平方根 | - | |
静的 メソッド |
Math.abs(x) | Number | xの絶対値を返す | - |
Math.sign(x) | Integer | xが正の数ならば1,負の数ならば-1,0ならば0を返す | V8以降 | |
Math.ceil(x) | Integer | xの小数点以下を切り上げた整数を返す | - | |
Math.floor(x) | Integer | xの小数点以下を切り捨てた整数を返す | - | |
Math.round(x) | Integer | xを四捨五入した整数を返す | - | |
Math.trunc(x) | Integer | xの整数部を返す | V8以降 | |
Math.exp(x) | Number | ネイピア数(オイラー数)のx乗を返す | - | |
Math.log(x) | Number | xの自然対数を返す | - | |
Math.log10(x) | Number | 底を10とするxの対数を返す | V8以降 | |
Math.log2(x) | Number | 底を2とするxの対数を返す | V8以降 | |
Math.max(x,y,…) | Number | x,y…の中で最大値を返す | - | |
Math.min(x,y,…) | Number | x,y…の値の中で最小値を返す | - | |
Math.pow(x,y) | Number | xのy乗を返す | - | |
Math.rondom() | Number | 0以上1未満の乱数を返す | - | |
Math.sqrt(x) | Number | xの平方根を返す | - | |
Math.cbrt(x) | Number | xの立方根を返す | V8以降 | |
Math.hypot(x,y…) | Number | x,y,…の二乗和の平方根を返す | V8以降 | |
Math.sin(x) | Number | xのサインを返す | - | |
Math.cos(x) | Number | xのコサインを返す | - | |
Math.tan(x) | Number | xのタンジェントを返す | - | |
Math.acos(x) | Number | xのアークコサインを返す | - | |
Math.asin(x) | Number | xのアークサインを返す | - | |
Math.atan(x) | Number | xのアークタンジェントを返す | - | |
Math.atan2(x) | Number | y/xのアークタンジェントを返す | - |