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

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

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

内容目录

Math.sin()函数用于返回数字的正弦值

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

语法

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

Math.sin( number )

参数

参数 描述
number Number类型需要计算正弦值的数字

返回值

返回值为Number类型。返回参数number的正弦值,返回值介于 [-1, 1] 之间。

如果参数不是数字,或无法转换为数字,则返回NaN

示例&说明

//输出 π/2 的正弦值
document.writeln( Math.sin( Math.PI/2 ) );	// 1

// 输出 0 的正弦值
document.writeln( Math.sin( 0 ) );	// 0

// 输出 0.5 的正弦值
document.writeln( Math.sin( 0.5 ) );	// 0.479425538604203

// 输出 3 的正弦值
document.writeln( Math.sin( 3 ) );	// 0.1411200080598672

// 输出 -1.7 的正弦值
document.writeln( Math.sin( -1.7 ) );	// -0.9916648104524686

// 输出字符串 "CodePlayer" 的正弦值
document.writeln( Math.sin( "CodePlayer" ) );	// NaN

运行代码

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

0 条评论

撰写评论

打开导航菜单