Coffeescript-math-atan
提供:Dev Guides
CoffeeScript Math-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