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) =
Note: The base-2 exponential function simply means .
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 variablesdouble x = -5.5, result;// using the exp2() functionresult = exp2(x);cout << "exp2(-5.5) = " << result << endl;return 0;}
Explanation
-
Line 9: We create the variables
xandresult. -
Line 12: We implement the
exp2()function on thexvariable and assign the output to theresultvariable. -
Line 13: We print the
resultvariable.