JavaScript常用數(shù)學函數(shù)用法示例
本文實例講述了JavaScript常用數(shù)學函數(shù)用法。分享給大家供大家參考,具體如下:
一、代碼
<script language="javascript"> <!-- document.write("歐拉常數(shù)e的值為(e屬性):"+Math.E+"<br>"); document.write("2的自然對數(shù)為(LN2屬性):"+Math.LN2+"<br>");//2的幾次方等于e document.write("10的自然對數(shù)為(LN10屬性):"+Math.LN10+"<br>");//10的幾次方等于e document.write("7的自然對數(shù)(log()方法):"+Math.log(7)+"<br>");//7的幾次方等于e document.write("0的自然對數(shù)(log()方法):"+Math.log(0)+"<br>"); document.write("-1的自然對數(shù)(log()方法):"+Math.log(-1)+"<br>"); document.write("2的自然對數(shù)(log()方法):"+Math.log(2)+"<br>");//2的幾次方等于e document.write("以2為基數(shù)的e的對數(shù)的值:"+Math.LOG2E+"<br>");//E的幾次方等于2 document.write("以10為基數(shù)的e的對數(shù)的值:"+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中的最大數(shù):"+Math.max(3,5)+"<br>"); document.write("3和5中的最小數(shù):"+Math.min(3,5)+"<br>"); document.write("-3和5中的最大數(shù):"+Math.max(-3,5)+"<br>"); document.write("-3和5中的最小數(shù):"+Math.min(-3,5)+"<br>"); document.write("3.5和3.4中的最大數(shù):"+Math.max(3.5,3.4)+"<br>"); document.write("3.5和3.4中的最小數(shù):"+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>
二、運行結(jié)果
歐拉常數(shù)e的值為(e屬性):2.718281828459045
2的自然對數(shù)為(LN2屬性):0.6931471805599453
10的自然對數(shù)為(LN10屬性):2.302585092994046
7的自然對數(shù)(log()方法):1.9459101490553132
0的自然對數(shù)(log()方法):-Infinity
-1的自然對數(shù)(log()方法):NaN
2的自然對數(shù)(log()方法):0.6931471805599453
以2為基數(shù)的e的對數(shù)的值:1.4426950408889633
以10為基數(shù)的e的對數(shù)的值: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中的最大數(shù):5
3和5中的最小數(shù):3
-3和5中的最大數(shù):5
-3和5中的最小數(shù):-3
3.5和3.4中的最大數(shù):3.5
3.5和3.4中的最小數(shù):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
PS:這里再為大家推薦幾款計算工具供大家進一步參考借鑒:
在線一元函數(shù)(方程)求解計算工具:
http://tools.jb51.net/jisuanqi/equ_jisuanqi
科學計算器在線使用_高級計算器在線計算:
http://tools.jb51.net/jisuanqi/jsqkexue
在線計算器_標準計算器:
http://tools.jb51.net/jisuanqi/jsq
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript數(shù)學運算用法總結(jié)》、《JavaScript操作DOM技巧總結(jié)》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》及《JavaScript遍歷算法與技巧總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
相關(guān)文章
jQuery和JavaScript節(jié)點插入元素的方法對比
本文主要介紹jQuery與JavaScript節(jié)點的插入方法,以及他們的具體代碼實現(xiàn)方法,大家可以對比下他們之間的不同,希望對大家編寫代碼有所幫助2016-11-11