pow
Compute the value of x raised to the power of y.
Interface Definition
C interface:
float powf(float x, float y);
double pow(double x, double y);
long double powl(long double x, long double y);
Fortran interface:
RES = POWF(X, Y);
RES = POW(X, Y);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data. |
Input |
y |
|
Floating-point value of the input data. |
Input |
Return Value
- If x is greater than 0 and y is a decimal, the result of x raised to the power of y is returned. Value range: (-INF, +INF)
- If x is -0 and y is a negative odd number, the return value is -∞. If x is ±0 and y is a negative number, the return value is +∞.
- If x is ±0 and y is a positive odd number, the return value is ±0. If x is ±0 and y is a positive number, the return value is +0.
- If x is ±1 and y is any value, the return value is +1.
- If x is any value and y is ±0, the return value is +1.
- If x is less than +0 and y is a decimal, the return value is NaN.
- If |x| is less than 1 and y is -∞, the return value is +∞. If |x| is greater than 1 and y is -∞, the return value is +0.
- If |x| is less than 1 and y is +∞, the return value is +0. If |x| is greater than 1 and y is +∞, the return value is +∞.
- If x is -∞ and y is a negative odd number, the return value is -0. If x is -∞ and y is a negative number, the return value is +0.
- If x is -∞ and y is a positive odd number, the return value is -∞. If x is -∞ and y is a positive number, the return value is +∞.
- If x is +∞ and y is less than +0, the return value is +0. If x is +∞ and y is greater than or equal to +0, the return value is +∞.
- If x and y are both large finite numbers, the return value is ±∞.
- If both x and y are NaN, the return value is 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 24 25 26 27 28 29 30 | double pi = acos(-1); // typical usage double x1 = 1.0, x2 = 2.0, x3 = 3.0, x4 = 4.0; double y1 = 4.0, y2 = -4.0, y3 = -3.0, y4 = 3.0; // special handling double a = 0.0, b = INFINITY, c = -INFINITY, d = NAN, e = 1.0; // print result printf("pow(1.0, 4.0) = %.15f\n", pow(x1, y1)); printf("pow(2.0, -4.0) = %.15f\n", pow(x2, y2)); printf("pow(3.0, -3.0) = %.15f\n", pow(x3, y3)); printf("pow(4.0, 3.0) = %.15f\n", pow(x4, y4)); printf("pow(1.0, 0.0) = %+.15f\n", pow(x1, a)); printf("pow(INFINITY, 1.0) = %+.15f\n", pow(b, x1)); printf("pow(-INFINITY, -1.0) = %+.15f\n", pow(c, -x1)); printf("pow(1.0, -INFINITY) = %+.15f\n", pow(x1, c)); printf("pow(1.0, NAN) = %+.15f\n", pow(x1, d)); printf("pow(NAN, -1.0) = %+.15f\n", pow(d, -x1)); /* * pow(1.0, 4.0) = 1.000000000000000 * pow(2.0, -4.0) = 0.062500000000000 * pow(3.0, -3.0) = 0.037037037037037 * pow(4.0, 3.0) = 64.000000000000000 * pow(1.0, 0.0) = +1.000000000000000 * pow(INFINITY, 1.0) = +inf * pow(-INFINITY, -1.0) = -0.000000000000000 * pow(1.0, -INFINITY) = +1.000000000000000 * pow(1.0, NAN) = +1.000000000000000 * pow(NAN, -1.0) = +nan * * */ |
Fortran interface:
REAL(8) :: X = 3.0
REAL(8) :: Y = -3.0
PRINT*, POW(X, Y)
!
! OUTPUT
! 0.037037037037037
!
Parent topic: Power and Root Functions