我要评分
获取效率
正确性
完整性
易理解

exp2

Return the value of 2 raised to the power of x.

Interface Definition

C interface:

float exp2f(float x);

double exp2(double x);

long double exp2l(long double x);

Fortran interface:

RES = EXP2F(X);

RES = EXP2(X);

Parameters

Parameter

Type

Description

Input/Output

x

  • For exp2f, x is of single-precision floating-point type.
  • For exp2, x is of double-precision floating-point type.
  • For exp2l, x is of long double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • The result y of 2 raised to the power of x is returned. y ∈ (0, +INF)
  • If the input is +0, the return value is +1.
  • If the input is -0, the return value is -1.
  • If input of exp2f is greater than 128, the return value is +∞. If the input of exp2 is greater than or equal to 1024, the return value is +∞.
  • If the input of exp2f is less than -150, the return value is +0. If the input of exp2 is less than or equal to -1075, the return value is +0.
  • If the input is +∞, the return value is +∞.
  • If the input is -∞, the return value is +0.
  • If the input is NaN, the return value is NaN.

Dependency

C: "km.h"

Examples

C interface:

    double pi = acos(-1); 
    // typical usage 
    double x1 = pi/2, x2 = 2.0; 
    // special handing 
    double a = 0.0, b = INFINITY, c = -INFINITY, d = NAN, e = 1024.0; 
    // print result 
        printf("exp2(pi/2) = %.15f\n", exp2(x1)); 
        printf("exp2(2.0) = %.15f\n", exp2(x2)); 
        printf("exp2(1024.0) = %.15f\n", exp2(e)); 
        printf("exp2(0.0) = %.15f\n", exp2(a)); 
        printf("exp2(INFINITY) = %.15f\n", exp2(b)); 
        printf("exp2(-INFINITY) = %.15f\n", exp2(c)); 
        printf("exp2(NAN) = %.15f\n", exp2(d)); 
    /* 
     *  exp2(pi/2) = 2.970686423552019 
     *  exp2(2.0) = 4.000000000000000 
     *  exp2(710.0) = inf 
     *  exp2(0.0) = 1.000000000000000 
     *  exp2(INFINITY) = inf 
     *  exp2(-INFINITY) = 0.000000000000000 
     *  exp2(NAN) = nan 
     * 
     * */

Fortran interface:

    REAL(8) :: X = 2 
    PRINT*,  EXP2(X) 
    ! 
    ! OUTPUT 
    !     4.000000000000000 
    !