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

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

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

内容目录

Math.cos()函数用于返回数字的余弦值

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

语法

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

Math.cos( number )

参数

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

返回值

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

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

示例&说明

//输出 π 的余弦值
document.writeln( Math.cos( Math.PI ) );	// -1

// 输出 0 的余弦值
document.writeln( Math.cos( 0 ) );	// 1

// 输出 0.5 的余弦值
document.writeln( Math.cos( 0.5 ) );	// 0.8775825618903728

// 输出 3 的余弦值
document.writeln( Math.cos( 3 ) );	// -0.9899924966004454

// 输出 -1.7 的余弦值
document.writeln( Math.cos( -1.7 ) );	// -0.12884449429552464

// 输出字符串 "365mini.com" 的余弦值
document.writeln( Math.cos( "365mini.com" ) );	// NaN

运行代码

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

0 条评论

撰写评论

打开导航菜单