
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
#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
#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
#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)
Advertisements