Rate This Document
Findability
Accuracy
Completeness
Readability

powr

Compute the value of x raised to the power of y, where x ≥ 0.

Interface Definition

C interface:

float powrf(float x, float y);

double powr(double x, double y);

Parameters

Parameter

Type

Description

Input/Output

x

  • For powrf, x is of single-precision floating-point type.
  • For powr, x is of double-precision floating-point type.

Floating-point value of the input data.

Input

y

  • For powrf, y is of single-precision floating-point type.
  • For powr, y is of double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • If x is greater than or equal to 0 and y is not a special value, the result of x raised to the power of y is returned. Value range: (0, +INF)
  • If x is less than 0, the return value is NaN.
  • Other combinations of special values are listed in the following table.

    Input Value (x)

    Input Value (y)

    Output Value (result)

    +0

    +0

    +1

    +0

    -0

    +1

    +0

    inf

    +0

    +0

    -inf

    inf

    +0

    snan

    nan

    +0

    -snan

    nan

    +0

    qnan

    nan

    +0

    -qnan

    nan

    -0

    +0

    +1

    -0

    -0

    +1

    -0

    inf

    +0

    -0

    -inf

    inf

    -0

    snan

    nan

    -0

    -snan

    nan

    -0

    qnan

    nan

    -0

    -qnan

    nan

    inf

    +0

    +1

    inf

    -0

    +1

    inf

    inf

    inf

    inf

    -inf

    +0

    inf

    snan

    nan

    inf

    -snan

    nan

    inf

    qnan

    nan

    inf

    -qnan

    nan

    -inf

    +0

    nan

    -inf

    -0

    nan

    -inf

    inf

    nan

    -inf

    -inf

    nan

    -inf

    snan

    nan

    -inf

    -snan

    nan

    -inf

    qnan

    nan

    -inf

    -qnan

    nan

    snan

    +0

    +1

    snan

    -0

    +1

    snan

    inf

    nan

    snan

    -inf

    nan

    snan

    snan

    nan

    snan

    -snan

    nan

    snan

    qnan

    nan

    snan

    -qnan

    nan

    -snan

    +0

    +1

    -snan

    -0

    +1

    -snan

    inf

    nan

    -snan

    -inf

    nan

    -snan

    snan

    nan

    -snan

    -snan

    nan

    -snan

    qnan

    nan

    -snan

    -qnan

    nan

    qnan

    +0

    +1

    qnan

    -0

    +1

    qnan

    inf

    nan

    qnan

    -inf

    nan

    qnan

    snan

    nan

    qnan

    -snan

    nan

    qnan

    qnan

    nan

    qnan

    -qnan

    nan

    -qnan

    +0

    +1

    -qnan

    -0

    +1

    -qnan

    inf

    nan

    -qnan

    -inf

    nan

    -qnan

    snan

    nan

    -qnan

    -snan

    nan

    -qnan

    qnan

    nan

    -qnan

    -qnan

    nan

Dependencies

C: "km.h"

Examples

C interface:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    // typical usage
    double x1 = 0.0, x2 = -0.0, x3 = 1.5, x4 = -2.5;
    // special handling
    double a = INFINITY, b = -INFINITY, c = NAN;
    // print result
    printf("powr(0.0, -0.0) = %.15f\n", powr(x1, x2));
    printf("powr(-0.0, 0.0) = %.15f\n", powr(x2, x1));
    printf("powr(1.5, 1.5) = %.15f\n", powr(x3, x3));
    printf("powr(-2.5, 1.5) = %.15f\n", powr(x4, x3));
    printf("powr(INFINITY, 1.5) = %.15f\n", powr(a, x3));
    printf("powr(-INFINITY, 1.5) = %.15f\n", powr(b, x3));
    printf("powr(NAN, NAN) = %.15f\n", powr(c, c));
    return 0;

    /*
     * powr(0.0, -0.0) = 1.000000000000000
     * powr(-0.0, 0.0) = 1.000000000000000
     * powr(1.5, 1.5) = 1.837117307087384
     * powr(-2.5, 1.5) = nan
     * powr(INFINITY, 1.5) = inf
     * powr(-INFINITY, 1.5) = nan
     * powr(NAN, NAN) = nan
     */