ในบทความนี้ เราจะพูดถึงการทำงาน ไวยากรณ์ และตัวอย่างของฟังก์ชัน std::exp2() สำหรับจำนวนเชิงซ้อนใน C++ STL
std::exp2() คืออะไร
ฟังก์ชัน std::exp2() สำหรับจำนวนเชิงซ้อนคือฟังก์ชัน inbuilt ใน C++ STL ซึ่งกำหนดไว้ในไฟล์ส่วนหัว
ฟังก์ชันนี้ส่งคืนค่า double, float หรือ long double ซึ่งก็คือ .
ไวยากรณ์
exp2(double n); exp2(float n); exp2(long double 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)