JavaScript Math Object
Math Object
Math object is used to perform mathematical tasks.
Math Date and String objects do not like that is a class object, so no constructor Math ().
grammar
var x = Math.PI; // returns PI
var y = Math.sqrt (16); // Returns the square root of 16
var y = Math.sqrt (16); // Returns the square root of 16
Math Object tutorial, please refer to the site of the JavaScript Math Object tutorial .
Math Object Properties
Attributes | description |
---|---|
E | Back arithmetic constant e, namely the natural logarithms (approximately 2.718). |
LN2 | Returns the natural logarithm (equivalent to about 0.693) 2. |
LN10 | Returns the natural logarithm of 10 (approximately equal to 2.302). |
LOG2E | Returns the base 2 logarithm of e (approximately equal to 1.414). |
LOG10E | Returns the base 10 logarithm of e (approximately equal to 0.434). |
PI | Back pi (approximately equal to 3.14159). |
SQRT1_2 | Return the reciprocal of the square root of 2 (approximately equal to 0.707). |
SQRT2 | Returns the square root of two (approximately equal to 1.414). |
Math object methods
方法 | 描述 |
---|---|
abs(x) | 返回 x 的绝对值。 |
acos(x) | 返回 x 的反余弦值。 |
asin(x) | 返回 x 的反正弦值。 |
atan(x) | 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值。 |
atan2(y,x) | 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)。 |
ceil(x) | 对数进行上舍入。 |
cos(x) | 返回数的余弦。 |
exp(x) | 返回 E x 的指数。 |
floor(x) | 对 x 进行下舍入。 |
log(x) | 返回数的自然对数(底为e)。 |
max(x,y,z,/en.,n) | 返回 x,y,z,/en.,n 中的最高值。 |
min(x,y,z,/en.,n) | 返回 x,y,z,/en.,n中的最低值。 |
pow(x,y) | 返回 x 的 y 次幂。 |
random() | 返回 0 ~ 1 之间的随机数。 |
round(x) | 把数四舍五入为最接近的整数。 |
sin(x) | 返回数的正弦。 |
sqrt(x) | 返回数的平方根。 |
tan(x) | 返回角的正切。 |