Home > Article > Web Front-end > What are the es6 math methods?
Math methods include: 1. Exponential methods, including pow(), sqrt(), etc.; 2. Logarithmic methods, including log(), log10(), etc.; 3. Algebraic methods, including abs() , sign(), etc.; 4. Trigonometric functions, including sin(), cos(), etc.; 4. random(), returns pseudo-random numbers.
The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
ES6 Math (Math Object)
Math object provides you with properties and methods for mathematical constants and functions. Unlike other global objects, Math is not a constructor. All properties and methods of Math are static, and you can use Math as an object without creating it.
Math object methods
1. Exponential method
The basic exponential method is Math. pow(), and has convenience functions for square roots, cube roots, and powers of e, as shown in the following table:
Method | Description |
---|---|
Math.pow(x, y) | Return x to the power of y |
Math.sqrt(x ) | Returns the square root of the number x |
Math.cbrt(x) | This method returns the number x The cube root of |
Math.exp(x) | is equivalent to Math.pow(Math.E,x) |
Math.expm1(x) | is equivalent to Math.exp(x) - 1 |
Math.hypot(x1, x2,...) | Returns the square root of the sum of parameters |
2. Right Math method
The basic natural logarithm method is Math.log(). In JavaScript, "log" means "natural logarithm". For convenience, ES6 introduces Math.log10.
Method | Description |
---|---|
Math.log(x) | Natural logarithm of x |
Math.log10(x) | Logarithm of base 10 |
Math.log2(x) | The logarithm of base 2 of x |
Math.log1p(x) | 1 The natural logarithm of x |
3. Miscellaneous algebraic methods
The following is a list of various algebraic methods and their descriptions.
Method | Description |
---|---|
Math.abs(x) | The absolute value of x |
Math.sign(x) | The sign of x: if x is a negative number, -1; if x is a positive number , then 1; if x is 0, 0 |
#The upper limit of x: the minimum value greater than or equal to x Integer | |
The base of x: the largest integer less than or equal to x | |
The integer part of x (all decimal places removed) | |
x rounds to the nearest integer | |
Return the minimum parameter | ##Math.max((x1, x2,...) |
Return the minimum parameter |
Math.sin(x) | |
---|---|
x sine of radians | Math.cos( x) |
xThe cosine of radians | Math.tan(x) |
xThe tangent of radians | Math.asin(x) |
The inverse sine (arcsin) of x (resulting in radians) |
| Math.acos(x)
The inverse cosine (arccos) of x (resulting in radians) | Math.atan (x) |
Arctan of x (resulting in radians) | Math.atan2(y, x0) |
Counterclockwise angle (radians) from the x-axis to the point (x, y) |
The Math.random() function returns a pseudo-random number between 0 (inclusive) and 1 (exclusive).
Example: Pseudo-random number generation (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 );Output
First Test Value : 0.5782922627404332 Second Test Value : 0.5624510529451072 Third Test Value : 0.9336334094405174 Fourth Test Value : 0.4002739654388279[Related recommendations:
javascript video tutorial
,web front-end】
The above is the detailed content of What are the es6 math methods?. For more information, please follow other related articles on the PHP Chinese website!