Calculates the base 2 exponential function of x (2 raised to the power x, where x is a single precision floating-point value).
Include
<math.h>
Prototype
float exp2f(float x);
Argument
x
Return Value
Returns the base 2 exponential of x
. On an overflow,
exp
returns inf
and on an underflow
exp
returns 0.
Remarks
A range error occurs if the magnitude of x
is too
large.
Example
#include <math.h>
#include <stdio.h>
#include <errno.h>
int main(void)
{
float x, y;
errno = 0;
x = 1.0;
y = exp2f(x);
if (errno)
perror("Error");
printf("The base 2 exponential of %f is %f\n", x, y);
errno = 0;
x = 10;
y = exp2f(x);
if (errno)
perror("Error");
printf("The base 2 exponential of %f is %f\n", x, y);
errno = 0;
x = -10;
y = exp2f(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