C++ STL 中的 exp2() 函式


在本文中,我們將討論 C++ STL 中 std::exp2() 函式在複數中的工作原理、語法和示例。

什麼是 std::exp2()?

複數的 std::exp2() 函式是 C++ STL 中的一個內建函式,它在 \ 或 \ 標頭檔案中定義。exp2() 函式用於計算給定數字的二進位制指數函式,也就是該數字的 2 為底的對數函式。

此函式返回值型別可以是 double、float 或 long double。

語法

exp2(double n);
exp2(float n);
exp2(long double n);

引數

該函式接受以下引數:

  • n − 指數的值。

返回值

此函式返回的底數為 2 的指數值,即 2^n。

示例

輸入

exp2(3.14);

輸出

0.11344

示例

 線上演示

#include <cmath>
#include <iostream>
using namespace std;
int main(){
   double var = -2.34;
   double hold = exp2(var);
   cout << "Value of exp2("<<var<<") is: "<< hold << endl;
   return 0;
}

輸出

Value of exp2(-2.34) is: 0.19751

示例

 線上演示

#include <cmath>
#include <iostream>
using namespace std;
int main(){
   int var = 10;
   int hold = exp2(var);
   cout << "Value of exp2("<<var<<") is: "<< hold << endl;
   return 0;
}

輸出

Value of exp2(10) is: 1024

示例

 線上演示

#include <cmath>
#include <iostream>
using namespace std;
int main(){
   int var = 1/0;
   int hold = exp2(var);
   cout << "Value of exp2("<<var<<") is: "<< hold << endl;
   return 0;
}

輸出

Floating point exception (core dumped)

更新於: 17-Apr-2020

91 次瀏覽

開啟您的職業生涯

完成課程以獲得認證

開始學習
廣告
© . All rights reserved.