当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


CoffeeScript Math atan()用法及代码示例


描述

这个atan()方法接受一个数字并以弧度返回其反正切值。此方法返回一个介于 -pi/2 和 pi/2 弧度之间的数值。

用法

下面给出的是atan()JavaScript 的方法。我们可以在 CoffeeScript 代码中使用相同的方法。

Math.atan( x )

示例

下面的例子演示了atan()CoffeeScript 中的方法。将此代码保存在具有名称的文件中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

打开command prompt并编译 .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);

现在,打开command prompt再次运行 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

相关用法


注:本文由纯净天空筛选整理自 CoffeeScript Math - atan()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。