What are the commonly used mathematical functions in JS?
This time I will bring you what common mathematical functions are in JS? , what are the precautions for implementing mathematical functions in JS? The following is a practical case, let’s take a look.
1. Code
<script> <!-- document.write("欧拉常数e的值为(e属性):"+Math.E+"<br>"); document.write("2的自然对数为(LN2属性):"+Math.LN2+"<br>");//2的几次方等于e document.write("10的自然对数为(LN10属性):"+Math.LN10+"<br>");//10的几次方等于e document.write("7的自然对数(log()方法):"+Math.log(7)+"<br>");//7的几次方等于e document.write("0的自然对数(log()方法):"+Math.log(0)+"<br>"); document.write("-1的自然对数(log()方法):"+Math.log(-1)+"<br>"); document.write("2的自然对数(log()方法):"+Math.log(2)+"<br>");//2的几次方等于e document.write("以2为基数的e的对数的值:"+Math.LOG2E+"<br>");//E的几次方等于2 document.write("以10为基数的e的对数的值:"+Math.LOG10E+"<br>");//E的几次方等于10 document.write(Math.SQRT1_2);//0.5的平方根 document.write(Math.SQRT2);//2的平方根 document.write("2的平方根:"+Math.sqrt(2)+"<br>"); document.write("4的平方根:"+Math.sqrt(4)+"<br>"); document.write("5的平方根:"+Math.sqrt(5)+"<br>"); document.write("10的平方根:"+Math.sqrt(10)); document.write("-2的绝对值:"+Math.abs(-2)+"<br>"); document.write("0的绝对值:"+Math.abs(0)+"<br>"); document.write("2的绝对值:"+Math.abs(2)+"<br>"); document.write("2.7的绝对值:"+Math.abs(2.7)+"<br>"); document.write("-2.7的绝对值:"+Math.abs(-2.7)); document.write("1的正弦值:"+Math.sin(1)+"<br>"); document.write("0的正弦值:"+Math.sin(0)+"<br>"); document.write("-1的正弦值:"+Math.sin(-1)+"<br>"); document.write("1的反正弦值的正弦值:"+Math.sin(Math.asin(1))+"<br>"); document.write("1的余弦值:"+Math.cos(1)+"<br>"); document.write("0的余弦值:"+Math.cos(0)+"<br>"); document.write("-1的余弦值:"+Math.cos(-1)+"<br>"); document.write("1的反余弦值的余弦值:"+Math.cos(Math.acos(1))+"<br>"); document.write("1的正切值:"+Math.tan(1)+"<br>"); document.write("0的正切值:"+Math.tan(0)+"<br>"); document.write("-1的正切值:"+Math.tan(-1)+"<br>"); document.write("1的反正切值的正切值:"+Math.tan(Math.atan(1))+"<br>"); document.write("3和5中的最大数:"+Math.max(3,5)+"<br>"); document.write("3和5中的最小数:"+Math.min(3,5)+"<br>"); document.write("-3和5中的最大数:"+Math.max(-3,5)+"<br>"); document.write("-3和5中的最小数:"+Math.min(-3,5)+"<br>"); document.write("3.5和3.4中的最大数:"+Math.max(3.5,3.4)+"<br>"); document.write("3.5和3.4中的最小数:"+Math.min(3.5,3.4)); document.write("对7.5进行四舍五入:"+Math.round(7.5)+"<br>"); document.write("对7.3进行四舍五入:"+Math.round(7.3)+"<br>"); document.write("对-7.8进行四舍五入:"+Math.round(-7.8)+"<br>"); document.write("对-7.3进行四舍五入:"+Math.round(-7.3)); document.write("对7.7进行上舍入:"+Math.ceil(7.7)+"<br>"); document.write("对7.3进行上舍入:"+Math.ceil(7.3)+"<br>"); document.write("对-7.8进行上舍入:"+Math.ceil(-7.8)+"<br>"); document.write("对-7.3进行上舍入:"+Math.ceil(-7.3)); document.write("对7.7进行下舍入:"+Math.floor(7.7)+"<br>"); document.write("对7.3进行下舍入:"+Math.floor(7.3)+"<br>"); document.write("对-7.8进行下舍入:"+Math.floor(-7.8)+"<br>"); document.write("对-7.3进行下舍入:"+Math.floor(-7.3)); //--> </script>
2. Running results
The value of Euler's constant e is (e attribute): 2.718281828459045
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
The natural logarithm of 2 is (LN2 attribute): 0.6931471805599453
The natural logarithm of 10 is (LN10 attribute): 2.302585092994046
7 The natural logarithm of (log() method): 1.9459101490553132 The natural logarithm of
0 (log() method): The natural logarithm of -Infinity
-1 (log() method): NaN
2 The natural logarithm (log() method): 0.6931471805599453
The value of the logarithm of e in base 2: 1.4426950408889633
The value of the logarithm of e in base 10: 0.4342944819032518
0.70710678118654761.41 421356237309512 The square root of: 1.4142135623730951
The square root of 4: 2
The square root of 5: 2.23606797749979
The square root of 10: 3.1622776601683795-2 The absolute value: 2
The absolute value of 0: The absolute value of 0
2 Value: 2
Absolute value of 2.7: 2.7
- Absolute value of 2.7: Sine value of 2.71: 0.8414709848078965
Sine value of 0: 0
- Sine value of 1: -0.8414709848078965
The sine of the arcsine of 1: 1 The cosine of the arcsine of 1: 0.5403023058681398 The cosine of
0: 1
- The cosine of 1: 0.5403023058681398 The cosine of the arcsine of
1: The tangent of 1
1: 1.5574077246549023 The tangent of 0: 0 The tangent of
-1: -1.5574077246549023 The tangent of the arctangent of
1: 0.9999999999999999
in 3 and 5 The maximum number: 5
The minimum number among 3 and 5: 3
-The maximum number among 3 and 5: 5
-The minimum number among 3 and 5:-3
3.5 and 3.4 The largest number in: 3.5
The smallest number between 3.5 and 3.4: 3.4 Rounding 7.5: 8
Rounding 7.3: 7
Rounding -7.8: -8
Rounding -7.3 Rounding up: -7 Rounding up 7.7: 8
Rounding up 7.3: 8
Rounding up -7.8: -7
Rounding up -7.3: -7 Rounding down 7.7: 7
Rounding down 7.3: 7
Rounding down -7.8: -8
Rounding down -7.3: -8
Recommended reading:
How to use webstorm to configure the nodejs environment and npmHow to use the Node.js sandbox environmentThe above is the detailed content of What are the commonly used mathematical functions in JS?. For more information, please follow other related articles on the PHP Chinese website!

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
