CoffeeScript 數學 - exp()



描述

exp() 方法接受一個數字並返回其 Ex 值。其中 x 為引數,E 為自然對數的底數尤拉常數

語法

以下是 JavaScript 中 exp() 方法的語法。我們可以在 CoffeeScript 程式碼中使用相同的方法。

Math.exp ( x )

示例

以下示例演示了 CoffeeScript 中 exp() 方法的用法。將此程式碼儲存在名為 math_exp.coffee 的檔案中。

value = Math.exp 1
console.log "The exponential value of 1 is : " + value 
         
value = Math.exp 52
console.log "The exponential value of 52 is : " + value 
         
value = Math.exp 0.78
console.log "The absolute value of 0.78 is : " + value  

開啟 命令提示符 並按如下所示編譯 .coffee 檔案。

c:\> coffee -c math_exp.coffee

編譯時,會生成以下 JavaScript。

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

  value = Math.exp(1);

  console.log("The exponential value of 1 is : " + value);

  value = Math.exp(52);

  console.log("The exponential value of 52 is : " + value);

  value = Math.exp(0.78);

  console.log("The absolute value of 0.78 is : " + value);

}).call(this);

現在,再次開啟 命令提示符 並按如下所示執行 CoffeeScript 檔案。

c:\> coffee math_exp.coffee

CoffeeScript 檔案執行時,將生成以下輸出。

The exponential value of 1 is : 2.718281828459045
The exponential value of 52 is : 3.831008000716576e+22
The absolute value of 0.78 is : 2.1814722654982015
coffeescript_math.htm
廣告