English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ exp2Usage and examples of the (x) function

C++ Library Function <cmath>

C ++in2(x) function calculates the exponentiation of x to the base2base.

This function calculates the exponentiation of x to the base<cmath>defined in the header file.

2x = exp2(x)

exp2function prototype [from C ++ 11Standard library starts]

double exp2(double x);
float exp2(float x);
long double exp2(long double x);
double exp2(T x); //is of integer type

exp2parameter

exp2function takes a single mandatory parameter (can be positive, negative, or 0).

exp2Returns value

exp2function returns[0, ∞]values within the range.

If the size of the result is too large to be represented by the return type value, the function will return HUGE_VAL with the correct sign and an overflow range error will occur.

Example1: exp2function in C ++how it works in C?

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	double x = -6.19, result;
	result = exp2(x);
	cout << "exp2(x) = " << result << endl;
	return 0;
}

When running the program, the output is:

exp2(x) = 0.013697

Example2has an integer type of exp2() Function

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	long int x = 14;
	double result;
	result = exp2(x);
	cout << "exp2(x) = " << result << endl;
	return 0;
}

When running the program, the output is:

exp2(x) = 16384

 C++ Library Function <cmath>