Calculates x
raised to the power y
.
Include
<math.h>
Prototype
double pow(double x, double y);
Arguments
x
y
Return Value
Returns x
raised to the power y
(x
y
).
Remarks
If y
is 0, pow
returns 1. If
x
is 0.0 and y
is less than 0,
pow
returns inf and a domain error occurs. If the result overflows
or underflows, a range error occurs.
Example
#include <math.h>
#include <stdio.h>
#include <errno.h>
int main(void)
{
double x,y,z;
errno = 0;
x = -2.0;
y = 3.0;
z = pow(x, y);
if (errno)
perror("Error");
printf("%f raised to %f is %f\n ", x, y, z);
errno = 0;
x = 3.0;
y = -0.5;
z = pow(x, y);
if (errno)
perror("Error");
printf("%f raised to %f is %f\n ", x, y, z);
errno = 0;
x = 4.0;
y = 0.0;
z = pow(x, y);
if (errno)
perror("Error");
printf("%f raised to %f is %f\n ", x, y, z);
errno = 0;
x = 0.0;
y = -3.0;
z = pow(x, y);
if (errno)
perror("Error");
printf("%f raised to %f is %f\n ", x, y, z);
}
Example Output
-2.000000 raised to 3.000000 is -8.000000
3.000000 raised to -0.500000 is 0.577350
4.000000 raised to 0.000000 is 1.000000
Error: domain error
0.000000 raised to -3.000000 is inf