📜  ES6-数学

📅  最后修改于: 2020-10-25 10:40:17             🧑  作者: Mango


数学对象为您提供数学常数和函数的属性和方法。与其他全局对象不同, Math不是构造函数。 Math的所有属性和方法都是静态的,可以通过将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.pow() ,并且有用于平方根,立方根和e的幂的便捷函数,如下表所示。

Sr.No Function & Description
1 Math.pow(x, y)

Returns x raised to the power y

2 Math.sqrt(x)

Returns the square root of the number x

3 Math.cbrt(x)

This method returns the cube root of a number x

4 Math.exp(x)

Equivalent to Math.pow(Math.E, x)

5 Math.expm1(x)

Equivalent to Math.exp(x) – 1

6 Math.hypot(x1, x2,…)

Returns the square root of the sum of arguments

对数函数

基本的自然对数函数是Math.log() 。在JavaScript中,“ log”表示“自然对数”。为了方便起见,ES6引入了Math.log10。

Sr.No Function & Description
1 Math.log(x)

Natural logarithm of x

2 Math.log10(x)

Base 10 logarithm of x

3 Math.log2(x)

Base 2 logarithm of x

4 Math.log1p(x)

Natural logarithm of 1 + x

杂项代数函数

以下是其他代数函数及其说明的列表。

Sr.No Function & Description
1 Math.abs(x)

Absolute value of x

2 Math.sign(x)

The sign of x: if x is negative,–1; if x is positive, 1; and if x is 0, 0

3 Math.ceil(x)

The ceiling of x: the smallest integer greater than or equal to x

4 Math.floor(x)

The floor of x: the largest integer less than or equal to x

5 Math.trunc(x)

The integral part of x (all fractional digits are removed)

6 Math.round(x)

x rounded to the nearest integer

7 Math.min(x1, x2,…)

Returns the minimum argument

8 Math.max((x1, x2,…)

Returns the minimum argument

三角函数

数学库中的所有三角函数都以弧度而不是度为单位。

Sr.No Function & Description
1 Math.sin(x)

Sine of x radians

2 Math.cos(x)

Cosine of x radians

3 Math.tan(x)

Tangent of x radians

4 Math.asin(x)

Inverse sine (arcsin) of x (result in radians)

5 Math.acos(x)

Inverse cosine (arccos) of x (result in radians)

6 Math.atan(x)

Inverse tangent (arctan) of x (result in radians)

7 Math.atan2(y, x0)

Counterclockwise angle (in radians) from the x-axis to the point (x, y)

Math.random()

Math.random()函数返回介于0(含)和1(不含)之间的伪随机数。

示例:伪随机数生成(PRNG)

var value1 = Math.random();  
console.log("First Test Value : " + value1 ); 

var value2 = Math.random();  
console.log("Second Test Value : " + value2 ); 

var value3 = Math.random();  
console.log("Third Test Value : " + value3 ); 

var value4 = Math.random(); 
console.log("Fourth Test Value : " + value4 );

输出

First Test Value : 0.5782922627404332 
Second Test Value : 0.5624510529451072 
Third Test Value : 0.9336334094405174 
Fourth Test Value : 0.4002739654388279