exp2 Function

Calculates the base 2 exponential function of x (2x, where x is a double precision floating-point value).

Include

<math.h>

Prototype

double exp2(double x);

Argument

x
value for which to return the exponential

Return Value

Returns 2x.

Remarks

A range error occurs if the magnitude of x is too large, and errno will be set to ERANGE.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <math.h>
#include <stdio.h>
#include <errno.h>

int main(void)
{
  double x, y;

  errno = 0;
  x = 1.0;
  y = exp2(x);
  if (errno)
    perror("Error");
  printf("The base 2 exponential of %f is %f\n", x, y);

  errno = 0;
  x = 10;
  y = exp2(x);
  if (errno)
    perror("Error");
  printf("The base 2 exponential of %f is %f\n", x, y);

  errno = 0;
  x = -10;
  y = exp2(x);
  if (errno)
    perror("Error");
  printf("The base 2 exponential of %f is %f\n", x, y);
}

Example Output

The base 2 exponential of 1.000000 is 2.000000
The base 2 exponential of 10.000000 is 1024.000000
The base 2 exponential of -10.000000 is 0.000977