JavaScript常用数学函数用法示例
作者:chengqiuming 时间:2024-04-10 16:14:21
本文实例讲述了JavaScript常用数学函数用法。分享给大家供大家参考,具体如下:
一、代码
<script language="javascript">
<!--
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>
二、运行结果
欧拉常数e的值为(e属性):2.718281828459045
2的自然对数为(LN2属性):0.6931471805599453
10的自然对数为(LN10属性):2.302585092994046
7的自然对数(log()方法):1.9459101490553132
0的自然对数(log()方法):-Infinity
-1的自然对数(log()方法):NaN
2的自然对数(log()方法):0.6931471805599453
以2为基数的e的对数的值:1.4426950408889633
以10为基数的e的对数的值:0.4342944819032518
0.70710678118654761.41421356237309512的平方根:1.4142135623730951
4的平方根:2
5的平方根:2.23606797749979
10的平方根:3.1622776601683795-2的绝对值:2
0的绝对值:0
2的绝对值:2
2.7的绝对值:2.7
-2.7的绝对值:2.71的正弦值:0.8414709848078965
0的正弦值:0
-1的正弦值:-0.8414709848078965
1的反正弦值的正弦值:1
1的余弦值:0.5403023058681398
0的余弦值:1
-1的余弦值:0.5403023058681398
1的反余弦值的余弦值:1
1的正切值:1.5574077246549023
0的正切值:0
-1的正切值:-1.5574077246549023
1的反正切值的正切值:0.9999999999999999
3和5中的最大数:5
3和5中的最小数:3
-3和5中的最大数:5
-3和5中的最小数:-3
3.5和3.4中的最大数:3.5
3.5和3.4中的最小数:3.4对7.5进行四舍五入:8
对7.3进行四舍五入:7
对-7.8进行四舍五入:-8
对-7.3进行四舍五入:-7对7.7进行上舍入:8
对7.3进行上舍入:8
对-7.8进行上舍入:-7
对-7.3进行上舍入:-7对7.7进行下舍入:7
对7.3进行下舍入:7
对-7.8进行下舍入:-8
对-7.3进行下舍入:-8
希望本文所述对大家JavaScript程序设计有所帮助。
来源:https://blog.csdn.net/chengqiuming/article/details/70140008
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解Hadoop 运行环境搭建过程
Mysql 远程连接配置实现的两种方法
[Oracle] 浅析令人抓狂的ORA-01555问题
python程序中调用其他程序的实现
Django url.py path name同一app下路由别名定义
![](https://img.aspxhome.com/file/2023/4/131304_0s.png)
vue使用v-for实现hover点击效果
![](https://img.aspxhome.com/file/2023/1/130041_0s.png)
python3中apply函数和lambda函数的使用详解
python实现视频读取和转化图片
asp清理站点缓存代码
Jupyter Notebook远程登录及密码设置操作
![](https://img.aspxhome.com/file/2023/5/118635_0s.jpg)
朴素贝叶斯算法的python实现方法
![](https://img.aspxhome.com/file/2023/4/82834_0s.png)
Python+Tensorflow+CNN实现车牌识别的示例代码
![](https://img.aspxhome.com/file/2023/0/101460_0s.jpg)
Pytorch中的model.train() 和 model.eval() 原理与用法解析
mysql数据库实现设置字段长度
ASP中SESSION无法保存问题的解决办法
![](https://img.aspxhome.com/file/UploadPic/201211/30/20121130203846956s.jpg)
PHP实现的DES加密解密类定义与用法示例
重构Python代码的六个实例
Python 实现数组相减示例
python format格式化和数字格式化
![](https://img.aspxhome.com/file/2023/5/86545_0s.png)