function
<cmath> <ctgmath>

exp2

     double exp2  (double x);      float exp2f (float x);long double exp2l (long double x);
     double exp2 (double x);      float exp2 (float x);long double exp2 (long double x);     double exp2 (T x);           // additional overloads for integral types
Compute binary exponential function
Returns the base-2 exponential function of x, which is 2 raised to the power x: 2x.

Header <tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).

Parameters

x
Value of the exponent.

Return Value

2 raised to the power of x.
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:

If an overflow range error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to ERANGE.
- And math_errhandling has MATH_ERREXCEPT set: FE_OVERFLOW is raised.

Example

1
2
3
4
5
6
7
8
9
10
11
12
/* exp2 example */
#include <stdio.h>      /* printf */
#include <math.h>       /* exp2 */

int main ()
{
  double param, result;
  param = 8.0;
  result = exp2 (param);
  printf ("2 ^ %f = %f.\n", param, result );
  return 0;
}

Output:

2 ^ 8.000000 is 256.000000.


See also