您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年08月05日 03:32

原创 JavaScript Math.tan() 函数详解

3142 次浏览 读完需要≈ 4 分钟

内容目录

Math.tan()函数用于返回一个数的正切值

该函数属于JavaScript的内置全局对象Math所有主流浏览器均支持该函数

语法

静态函数Math.tan()的语法如下:

Math.tan( number )

参数

参数 描述
number Number类型指定的数,以计算该数的正切值

返回值

Math.tan()的返回值为Number类型。返回number的正切值。

传入的参数不能为NaN值,否则返回NaN

示例&说明

document.writeln( Math.tan( 1.512 ) ); // 16.98826189952931

document.writeln( Math.tan( -2.3 ) ); // 1.1192136417341325

document.writeln( Math.tan( 0 ) ); // 0

// 在数学上,tan的定义域为 number ≠ kπ + π/2,也就是说number不能为 π/2
// 但是在JavaScript中,由于精度的问题,Math.tan( Math.PI / 2 )仍然是有值的
// 并且不同浏览器的计算结果存在一些细微的精度差异
document.writeln( Math.tan( Math.PI / 2 ) ); // 16331239353195370(IE/FireFox) | 16331778728383844(Chrome)

// 传入的参数为NaN值
document.writeln( Math.tan( "CodePlayer" ) ); // NaN

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单