當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


CoffeeScript Math asin()用法及代碼示例


描述

這個asin()方法接受一個整數值並以弧度返回其反正弦值。對於介於 -1 和 1 之間的 x,asin 方法返回介於 -pi/2 和 pi/2 弧度之間的數值。如果 number 的值超出此範圍,則返回 NaN。

用法

下麵給出的是asin()JavaScript 的方法。我們可以在 CoffeeScript 代碼中使用相同的方法。

Math.asin( x )

示例

下麵的例子演示了asin()CoffeeScript 中的方法。將此代碼保存在具有名稱的文件中math_asin.coffee

value = Math.asin -1
console.log "The arc sine value of -1 is:" + value 
         
value = Math.asin null
console.log "The arc sine value of null is:" + value 
         
value = Math.asin 20
console.log "The arc sine value of 20 is:" + value

打開command prompt並編譯 .coffee 文件,如下所示。

c:\> coffee -c math_asin.coffee

在編譯時,它會為您提供以下 JavaScript。

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

  value = Math.asin(-1);

  console.log("The arc sine value of -1 is:" + value);

  value = Math.asin(null);

  console.log("The arc sine value of null is:" + value);

  value = Math.asin(20);

  console.log("The arc sine value of 20 is:" + value);

}).call(this);

現在,打開command prompt再次運行 CoffeeScript 文件,如下所示。

c:\> coffee math_asin.coffee

在執行時,CoffeeScript 文件產生以下輸出。

The arc sine value of -1 is:-1.5707963267948966
The arc sine value of null is:0
The arc sine value of 20 is:NaN

相關用法


注:本文由純淨天空篩選整理自 CoffeeScript Math - asin()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。