pow(), powf(), powl() — Raise to power
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
Format
#include <math.h>
double pow(double x, double y);
double pow(double x, int y); /* C++ only */
float pow(float x, int y); /* C++ only */
float pow(float x, float y); /* C++ only */
long double pow(long double x, int y); /* C++ only */
long double pow(long double x, long double y); /* C++ only */
float powf(float x, float y);
long double powl(long double x, long double y);
General description
Returned value
If successful, the pow(), powf(), and powl() functions return the value of x to the power of y.
If y is 0, the function returns 1.
If x is negative and y is non-integral, the function sets errno to EDOM and returns -HUGE_VAL. If the correct value is outside the range of representable values, ±HUGE_VAL is returned according to the sign of the value, and the value of ERANGE is stored in errno.
Special behavior for IEEE: If x is negative or 0, then the y parameter must be an integer. If y is 0, the function returns 1.0 for all x parameters.
If an overflow occurs, the function returns HUGE_VAL and sets errno to ERANGE.
If both x and y are negative, the function returns NaNQ and sets errno to EDOM.
Example
/* CELEBP05
This example calculates the value of 2**3.
*/
#include <math.h>
#include <stdio.h>
int main(void)
{
double x, y, z;
x = 2.0;
y = 3.0;
z = pow(x,y);
printf("%lf to the power of %lf is %lf\n", x, y, z);
}
2.000000 to the power of 3.000000 is 8.000000