js 的 Math 庫有很多有用的方法數組
Math.min(5,2,3) // 打印 2 Math.max(5,2,3) // 打印 5
獲取數組的最大最小值app
Math.min.apply(null, [5,2,3]) // 打印 2 Math.max.apply(null, [5,2,3]) // 打印 5
Math.random() // 隨機獲取 0 ~ 1 的值
Math.sqrt(15) // 開方
Math.pow(x, y) // 返回 x 的 y 次冪。dom
Math.abs(x)code
Math.round() //把數四捨五入爲最接近的整數。
Math.floor() // 向下取整
Math.ceil() // 向上取整隨機數
Math.exp() // 返回 e 的指數。
Math.log() // 返回數的天然對數(底爲e)。方法
Math.asin(x) //返回數的反正弦值。
Math.acos(x) //返回數的反餘弦值。
Math.atan(x) // 以介於 -PI/2 與 PI/2 弧度之間的數值來返回 x 的反正切值。
Math.atan2(y,x) //返回從 x 軸到點 (x,y) 的角度(介於 -PI/2 與 PI/2 弧度之間)。apply
Math.E //返回算術常量 e,即天然對數的底數(約等於2.718)。
Math.LN2 // 返回 2 的天然對數(約等於0.693)。
Math.LN10 //返回 10 的天然對數(約等於2.302)。
Math.LOG2E //返回以 2 爲底的 e 的對數(約等於 1.414)。
Math.LOG10E //返回以 10 爲底的 e 的對數(約等於 1.414)。
Math.PI // 返回圓周率(約等於3.14159)。
Math.SQRT1_2 // 返回返回 2 的平方根的倒數(約等於 0.707)。
Math.SQRT2 // 返回 2 的平方根(約等於 1.414)。co