📅  最后修改于: 2020-12-18 05:03:51             🧑  作者: Mango
数学对象为您提供数学常数和函数的属性和方法。与其他全局对象不同, Math不是构造函数。 Math的所有属性和方法都是静态的,可以通过将Math用作对象来调用而不创建它。
因此,您将常数pi称为Math.PI ,并将正弦函数称为Math.sin(x) ,其中x是方法的参数。
调用Math属性和方法的语法如下
var pi_val = Math.PI;
var sine_val = Math.sin(30);
这是Math的所有属性及其描述的列表。
Sr.No. | Property & Description |
---|---|
1 | E \
Euler’s constant and the base of natural logarithms, approximately 2.718. |
2 | LN2
Natural logarithm of 2, approximately 0.693. |
3 | LN10
Natural logarithm of 10, approximately 2.302. |
4 | LOG2E
Base 2 logarithm of E, approximately 1.442. |
5 | LOG10E
Base 10 logarithm of E, approximately 0.434. |
6 | PI
Ratio of the circumference of a circle to its diameter, approximately 3.14159. |
7 | SQRT1_2
Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707. |
8 | SQRT2
Square root of 2, approximately 1.414. |
在以下各节中,我们将通过一些示例来演示Math属性的用法。
这是与Math对象关联的方法及其说明的列表
Sr.No. | Method & Description |
---|---|
1 | abs()
Returns the absolute value of a number. |
2 | acos()
Returns the arccosine (in radians) of a number. |
3 | asin()
Returns the arcsine (in radians) of a number. |
4 | atan()
Returns the arctangent (in radians) of a number. |
5 | atan2()
Returns the arctangent of the quotient of its arguments. |
6 | ceil()
Returns the smallest integer greater than or equal to a number. |
7 | cos()
Returns the cosine of a number. |
8 | exp()
Returns EN, where N is the argument, and E is Euler’s constant, the base of the natural logarithm. |
9 | floor()
Returns the largest integer less than or equal to a number. |
10 | log()
Returns the natural logarithm (base E) of a number. |
11 | max()
Returns the largest of zero or more numbers. |
12 | min()
Returns the smallest of zero or more numbers. |
13 | pow()
Returns base to the exponent power, that is, base exponent. |
14 | random()
Returns a pseudo-random number between 0 and 1. |
15 | round()
Returns the value of a number rounded to the nearest integer. |
16 | sin()
Returns the sine of a number. |
17 | sqrt()
Returns the square root of a number. |
18 | tan()
Returns the tangent of a number. |
19 | toSource()
Returns the string “Math”. |
在以下各节中,我们将通过一些示例来演示与Math相关的方法的用法。