exp2() function in C++ STL Last Updated : 03 Feb, 2023 Comments Improve Suggest changes Like Article Like Report The exp2() is a builtin function in C++ STL that computes the base-2 exponential function of a given number. It can also be written as 2num. Syntax: exp2(data_type num) Parameter: The function accepts a single mandatory parameter num which specifies the value of the exponent. It can be positive, negative or 0. The parameter can be of type double, float or long double.Return Value: It returns either a double, float or long double value which is equivalent to 2num. Time Complexity: O(1)Space Complexity: O(1) Program 1: CPP // C++ program to illustrate the // exp2() function for negative double numbers #include <cmath> #include <iostream> using namespace std; int main() { double n = -3.14; double ans = exp2(n); cout << "exp2(-3.14) = " << ans << endl; return 0; } Output: exp2(-3.14) = 0.11344 Program 2: CPP // C++ program to illustrate the // exp2() function for positive numbers #include <cmath> #include <iostream> using namespace std; int main() { int n = 6; int ans = exp2(n); cout << "exp2(6) = " << ans << endl; return 0; } Output: exp2(6) = 64 Program 3: CPP // C++ program to illustrate the // exp2() function for 0 #include <cmath> #include <iostream> using namespace std; int main() { int n = 0; int ans = exp2(n); cout << "exp2(0) = " << ans << endl; return 0; } Output: exp2(0) = 1 Errors and Exceptions: If the magnitude of the result is too large to be represented by a value of the return type, the function returns HUGE_VAL (or HUGE_VALF or HUGE_VALL) with the proper sign, and an overflow range error occurs. Below program illustrate the error. CPP // C++ program to illustrate the // exp2() function for range overflow #include <cmath> #include <iostream> using namespace std; int main() { // overflow will occur as 2^100 will not // fit to int data-type int n = 100; int ans = exp2(n); cout << "exp2(100) = " << ans << endl; return 0; } Output: exp2(100) = -2147483648 Comment More infoAdvertise with us Next Article exp2() function in C++ STL I IshwarGupta Follow Improve Article Tags : C++ STL CPP-Library C-Library cpp-math +1 More Practice Tags : CPPSTL Similar Reads strol() function in C++ The strtol() function in C++ interprets the contents of a string as an integral number of the specified base and return its value as a long int.This function also sets an end pointer that points to the first character after the last valid numeric character of the string, if there is no such characte 3 min read std::function in C++ The std::function() in C++ is a function wrapper class which can store and call any function or a callable object. In this article, we will learn about std::function in C++ and how to use it in different cases.Table of ContentWhat is std::function in C++?Example of std::functionMember Functions of s 5 min read list empty() function in C++ STL The list::empty() is a built-in function in C++ STL that is used to check whether a particular list container is empty or not. This function does not modify the list, it simply checks whether a list is empty or not, i.e. the size of the list is zero or not. Syntaxlist_name.empty() Parameters This fu 1 min read valarray exp() function in C++ The exp() function is defined in valarray header file. This function is used to calculate e raised to the power equal to the value of the element in valarray. Syntax: exp(varr); Parameter: This function takes a mandatory parameter varr which represents valarray. Returns: This function returns a vala 2 min read list end() function in C++ STL The list::end() is a built-in function in C++ STL which is used to get an iterator to past the last element. By past the last element it is meant that the iterator returned by the end() function return an iterator to an element which follows the last element in the list container. It can not be used 2 min read Like