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

