CoffeeScript 数学 - acos()



说明

acos() 方法接受一个数字并返回它的反余弦(弧度)。它会返回介于 0 和 pi 弧度之间的数字,对应的 x 为 -1 到 1。如果 number 的值超出这个范围,则返回 NaN。

语法

以下是 JavaScript 的 acos() 方法语法。我们可以在 CoffeeScript 代码中使用相同的方法。

Math.acos( x )

示例

下面的示例演示了在 CoffeeScript 中使用 acos() 方法。将此代码保存在名为 math_acos.coffee 的文件中。

value = Math.acos -1
console.log "The arc cosine value of -1 is : " + value 
         
value = Math.acos null 
console.log "The arc cosine value of null is : " + value 
         
value = Math.acos 20
console.log "The arc cosine value of 20 is : " + value

打开命令提示符并编译 .coffee 文件,如下所示。

c:\> coffee -c math_acos.coffee

编译后,它会给你以下 JavaScript 代码。

// Generated by CoffeeScript 1.10.0
(function() {
  var value;

  value = Math.acos(-1);

  console.log("The arc cosine value of -1 is : " + value);

  value = Math.acos(null);

  console.log("The arc cosine value of null is : " + value);

  value = Math.acos(20);

  console.log("The arc cosine value of 20 is : " + value);

}).call(this);

现在,再次打开命令提示符,并运行 CoffeeScript 文件,如下所示。

c:\> coffee math_acos.coffee

执行后,CoffeeScript 文件会产生以下输出。

The arc cosine value of -1 is : 3.141592653589793
The arc console value of null is : 1.5707963267948966
The arc cosine value of 20 is : NaN
coffeescript_math.htm
广告
© . All rights reserved.