# powl Function

Calculates x raised to the power y.

Include

<math.h>

Prototype

long double powl(long double x, long double y);

Arguments

 x the base y the exponent

Return Value

Returns x raised to the power y (xy).

Remarks

If x is finite and negative and y is finite and not an integer value, a domain error will occur and errno will be set to EDOM.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <math.h>
#include <stdio.h>
#include <errno.h>

int main(void)
{
long double x,y,z;

errno = 0;
x = -2.0;
y = 3.0;
z = powl(x, y);
if (errno)
perror("Error");
printf("%Lf raised to %Lf is %Lf\n ", x, y, z);

errno = 0;
x = 3.0;
y = -0.5;
z = powl(x, y);
if (errno)
perror("Error");
printf("%Lf raised to %Lf is %Lf\n ", x, y, z);

errno = 0;
x = 4.0;
y = 0.0;
z = powl(x, y);
if (errno)
perror("Error");
printf("%Lf raised to %Lf is %Lf\n ", x, y, z);

errno = 0;
x = 0.0;
y = -3.0;
z = pow (x, y);
if (errno)
perror("Error");
printf("%Lf raised to %Lf is %Lf\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