Coffeescript-math-tan

提供:Dev Guides
移動先:案内検索

CoffeeScript Math-tan()

説明

  • tan()*メソッドは数値を受け入れ、そのタンジェント値を返します。

構文

JavaScriptの* tan()*メソッドの構文は次のとおりです。 CoffeeScriptコードで同じメソッドを使用できます。

Math.tan ( x )

次の例は、CoffeeScriptでの* tan()メソッドの使用方法を示しています。 このコードを *math_tan.coffee という名前のファイルに保存します。

value = Math.tan -30
console.log "The tangent value of -30 is : " + value

value = Math.tan 90
console.log "The tangent value of 90 is : " + value

value = Math.tan(2*Math.PI/180)
console.log "The tangent value of 2*Math.PI/180 is : " + value
  • Node.jsコマンドプロンプト*を開き、以下に示すように.coffeeファイルをコンパイルします。
c:\> coffee -c math_tan.coffee

コンパイル時に、次のJavaScriptが提供されます。

//Generated by CoffeeScript 1.10.0
(function() {
  var value;

  value = Math.tan(-30);

  console.log("The tangent value of -30 is : " + value);

  value = Math.tan(90);

  console.log("The tangent value of 90 is : " + value);

  value = Math.tan(2 * Math.PI/180);

  console.log("The tangent value of 2*Math.PI/180 is : " + value);

}).call(this);

次に、* Node.jsコマンドプロンプト*を再度開き、以下に示すようにCoffeeScriptファイルを実行します。

c:\> coffee math_tan.coffee

CoffeeScriptファイルを実行すると、次の出力が生成されます。

The tangent value of -30 is : 6.405331196646276
The tangent value of 90 is : -1.995200412208242
The tangent value of 2*Math.PI/180 is : 0.03492076949174773