Calculates x raised to the power y.
Include
<math.h>
Prototype
float powf(float x, float 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)
{
float x,y,z;
errno = 0;
x = -2.0F;
y = 3.0F;
z = powf (x, y);
if (errno)
perror("Error");
printf("%f raised to %f is %f\n ", x, y, z);
errno = 0;
x = 3.0F;
y = -0.5F;
z = powf (x, y);
if (errno)
perror("Error");
printf("%f raised to %f is %f\n ", x, y, z);
errno = 0;
x = 0.0F;
y = -3.0F;
z = powf (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
Error: domain error
0.000000 raised to -3.000000 is inf