JavaScript cos() 方法


定义和用法

cos() 方法可返回一个数字的余弦值。

语法
  1. Math.cos(x)
参数 描述
x 必需。必须是一个数值。
返回值

x 的余弦值。返回的是 -1.0 到 1.0 之间的数。


实例

在本例中,我们将返回不同数值的余弦值:

  1. <html>
  2. <body>
  3. <script type="text/javascript">
  4. document.write(Math.cos(3) + "<br />")
  5. document.write(Math.cos(-3) + "<br />")
  6. document.write(Math.cos(0) + "<br />")
  7. document.write(Math.cos(Math.PI) + "<br />")
  8. document.write(Math.cos(2*Math.PI))
  9. </script>
  10. </body>
  11. </html>

输出:

  1. -0.9899924966004454
  2. -0.9899924966004454
  3. 1
  4. -1
  5. 1

分类导航