What is the exp2() function in C++?

Overview

The exp2() function is used to return the base-2 exponential function of a given parameter value, x.

Mathematically, exp2() is given as follows:

exp2(x) = 2x2^{x}

Note: The base-2 exponential function simply means 2x2^{x}.

Syntax

double exp2(double x);
float exp2(float x);
long double exp2(long double x);

Parameters

This function takes a single parameter x, which is a number that can be positive, negative, or zero.

Return value

The exp2() function returns the value of numbers within 0 and ∞.

Example

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// creating our variables
double x = -5.5, result;
// using the exp2() function
result = exp2(x);
cout << "exp2(-5.5) = " << result << endl;
return 0;
}

Explanation

  • Line 9: We create the variables x and result.

  • Line 12: We implement the exp2() function on the x variable and assign the output to the result variable.

  • Line 13: We print the result variable.

Free Resources