CoffeeScript 数学 - atan2()
描述
atan2() 方法接受两个数字并返回以弧度为单位的反正切值。 此方法返回一个介于 -pi 和 pi 之间的数值,表示 (x, y) 点的角度 theta。
语法
下面给出的是 JavaScript 的 atan2() 方法的语法。 我们可以在 CoffeeScript 代码中使用相同的方法。
Math.atan( x )
示例
以下示例演示了 CoffeeScript 中 atan2() 方法的用法。 将此代码保存在名为 math_atan2.coffee 的文件中。
value = Math.atan2 90,15
console.log "The arc tangent value of 90,15 is : " + value
value = Math.atan2 15,90
console.log "The arc tangent value of 15,90 is : " + value
value = Math.atan2 0,-0
console.log "The arc tangent value of 0,-0 is : " + value
value = Math.atan2 +Infinity, -Infinity
console.log "The arc tangent value of +Infinity, -Infinity is : " + value
打开命令提示符并编译.coffee 文件,如下所示。
c:\> coffee -c math_atan2.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_atan2.coffee
执行时,CoffeeScript 文件产生以下输出。
The arc tangent value of 90,15 is : 1.4056476493802699 The arc tangent value of 15,90 is : 0.16514867741462683 The arc tangent value of 0,-0 is : 3.141592653589793 The arc tangent value of +Infinity, -Infinity is : 2.356194490192345

