C++ STL 中的 exp2() 函式
在本文中,我們將討論 C++ STL 中 std::exp2() 函式在複數中的工作原理、語法和示例。
什麼是 std::exp2()?
複數的 std::exp2() 函式是 C++ STL 中的一個內建函式,它在 \
此函式返回值型別可以是 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)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP