VOOZH about

URL: https://www.geeksforgeeks.org/cpp/exp2-function-in-c-stl/

⇱ exp2() function in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

exp2() function in C++ STL

Last Updated : 3 Feb, 2023

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


Output: 
exp2(-3.14) = 0.11344

 

Program 2


Output: 
exp2(6) = 64

 

Program 3


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. 


Output: 
exp2(100) = -2147483648

 
Comment
Article Tags: