Namespaces
Variants
Views
Actions

exp2

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
Exponential functions
exp2
(C99)
(C99)
(C99)
(C99)
Power functions
(C99)
(C99)
Trigonometric and hyperbolic functions
(C99)
(C99)
(C99)
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Nearest integer floating point operations
(C99)(C99)(C99)
(C99)
(C99)(C99)(C99)
Floating point manipulation functions
(C99)(C99)
(C99)
(C99)
Classification
(C99)
(C99)
(C99)
Macro constants
 
Defined in header <math.h>
float       exp2f( float n );
(since C99)
double      exp2( double n );
(since C99)
long double exp2l( long double n );
(since C99)

Computes 2 raised to the given power n

Contents

[edit] Parameters

n - floating point value

[edit] Return value

2 raised to the n (i.e. 2n)

If the result is too large for the underlying type, range error occurs and HUGE_VAL is returned.

[edit] Example

#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <string.h>
 
int main()
{
    printf("exp2(1.0)        = %.1f\n", exp2(1.0));
    printf("log2(2.0)        = %.1f\n", log2(2.0));   /* inverse of exp2 */
    printf("exp2(+0.0)       = %.1f\n", exp2(+0.0));
    printf("exp2(-0.0)       = %.1f\n", exp2(-0.0));
    printf("exp2(+INFINITY)  = %.1f\n", exp2(+INFINITY));
    printf("exp2(-INFINITY)  = %.1f\n", exp2(-INFINITY));
    printf("exp2(NAN)        = %.1f\n", exp2(NAN));
    printf("\n");
 
    /* inf but no range error */
    errno = 0;
    printf("exp2(1024.0)     = %f\n", exp2(1024.0));
    printf("%s\n",strerror(errno));
 
    /* range error */
    errno = 0;
    printf("exp2(1025.0)     = %f\n", exp2(1025.0));
    printf("%s\n",strerror(errno));
 
    return 0;
}

Possible output:

exp2(1.0)        = 2.0
log2(2.0)        = 1.0
exp2(+0.0)       = 1.0
exp2(-0.0)       = 1.0
exp2(+INFINITY)  = inf
exp2(-INFINITY)  = 0.0
exp2(NAN)        = nan
 
exp2(1024.0)     = inf
Success
exp2(1025.0)     = inf
Numerical result out of range

[edit] See also

returns e raised to the given power (ex)
(function) [edit]
computes natural (base e) logarithm (to base e) (ln(x))
(function) [edit]
raises a number to the given power (xy)
(function) [edit]