CoffeeScript 数学 - asin()
描述
asin() 方法接受一个整数值并以弧度返回其反正弦值。 asin 方法返回 -pi/2 和 pi/2 弧度之间的数值,x 在 -1 和 1 之间。如果 number 的值超出此范围,则返回 NaN。
语法
下面给出的是 JavaScript 的 asin() 方法的语法。 我们可以在 CoffeeScript 代码中使用相同的方法。
Math.asin( x )
示例
以下示例演示了 CoffeeScript 中 asin() 方法的用法。 将此代码保存在名为 math_asin.coffee 的文件中。
value = Math.asin -1
console.log "The arc sine value of -1 is : " + value
value = Math.asin null
console.log "The arc sine value of null is : " + value
value = Math.asin 20
console.log "The arc sine value of 20 is : " + value
打开命令提示符并编译.coffee 文件,如下所示。
c:\> coffee -c math_asin.coffee
在编译时,它会提供以下 JavaScript。
// Generated by CoffeeScript 1.10.0
(function() {
var value;
value = Math.asin(-1);
console.log("The arc sine value of -1 is : " + value);
value = Math.asin(null);
console.log("The arc sine value of null is : " + value);
value = Math.asin(20);
console.log("The arc sine value of 20 is : " + value);
}).call(this);
现在,再次打开命令提示符,然后运行 CoffeeScript 文件,如下所示。
c:\> coffee math_asin.coffee
执行时,CoffeeScript 文件产生以下输出。
The arc sine value of -1 is : -1.5707963267948966 The arc sine value of null is : 0 The arc sine value of 20 is : NaN

