当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 在JavaScript中使用对数Math.log()方法的教程

在JavaScript中使用对数Math.log()方法的教程

2019年08月02日  | 移动技术网IT编程  | 我要评论

 这个方法返回一个数的自然对数(底数是e)。如果数的值是负的,则返回值始终为nan。
语法

math.log( x ) ;

下面是参数的详细信息:

  •     x : 一个数字.

返回值:

  • 返回一个数字的自然对数(底数为e)。

例子:

<html>
<head>
<title>javascript math log() method</title>
</head>
<body>
<script type="text/javascript">

var value = math.log(10);
document.write("first test value : " + value ); 
 
var value = math.log(0);
document.write("<br />second test value : " + value ); 

var value = math.log(-1);
document.write("<br />third test value : " + value ); 

var value = math.log(100);
document.write("<br />fourth test value : " + value ); 
</script>
</body>
</html>

这将产生以下结果:

first test value : 2.302585092994046
second test value : -infinity
third test value : nan
fourth test value : 4.605170185988092 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网