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 y is 0, powl returns 1. If x is 0.0 and y is less than 0, powl 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)
{
  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