exp2() function in C++ STL


In this article we will be discussing the working, syntax and examples of std::exp2() function for complex numbers in C++ STL.

What is std::exp2()?

std::exp2() function for complex numbers is an inbuilt function in C++ STL, which is defined in <cmath> or <ctgmath> header file. exp2() function is used for computing the binary exponential function that is the base-2 exponential function of a given number.

This function returns either double, float or long double value which is .

Syntax

exp2(double n);
exp2(float n);
exp2(long double n);

Parameters

The function accepts the following parameter(s) −

  • n − It is a value of the exponent.

Return value

This function returns the base-2 exponential value i.e. 2^n .

Example

Input

exp2(3.14);

Output

0.11344

Example

 Live Demo

#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;
}

Output

Value of exp2(-2.34) is: 0.19751

Example

 Live Demo

#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;
}

Output

Value of exp2(10) is: 1024

Example

 Live Demo

#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;
}

Output

Floating point exception (core dumped)

Updated on: 17-Apr-2020

51 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements