該函數計算給定數字的基數為 2 的 index 函數。
假設一個數字是 'x':
exp2(x) = 2<sup>x</sup>
用法
float exp2(float x);
double exp2(double x);
long double exp2(long double x);
double exp2(integral x);
參數
x: 它是 index 的值。
返回值
它返回,2 的 x 次方。
例子1
讓我們看一個簡單的例子,當 x 的值為正時
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x= 4;
std::cout << "Value of x is:" <<x <<std::endl;
cout<<"exp2(x) = "<<exp2(4);
return 0;
}
輸出:
Value of x is:4 exp2(x) = 16
例子2
當 x 的值為負時,讓我們看一個簡單的例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x= -2;
std::cout << "Value of x is:" <<x <<std::endl;
cout<<"exp2(x) = "<<exp2(x);
return 0;
}
輸出:
Value of x is:-2 exp2(x) = 0.25
相關用法
- C++ Math exp()用法及代碼示例
- C++ Math expm1()用法及代碼示例
- C++ Math erfc()用法及代碼示例
- C++ Math erf()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math fabs()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math fdim()用法及代碼示例
- C++ Math isfinite()用法及代碼示例
- C++ Math sinh()用法及代碼示例
- C++ Math scalbln()用法及代碼示例
- C++ Math cosh()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math exp2()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。