function
<cmath> <ctgmath>

pow

double pow (double base, double exponent);
     double pow  (double base     , double exponent);
      float powf (float base      , float exponent);
long double powl (long double base, long double exponent);
     double pow (double base     , double exponent);
      float pow (float base      , float exponent);
long double pow (long double base, long double exponent);
     double pow (double base     , int exponent);
long double pow (long double base, int exponent);
     double pow (double base     , double exponent);
      float pow (float base      , float exponent);
long double pow (long double base, long double exponent);
     double pow (Type1 x         , Type2 y);              // additional overloads
Raise to power
Returns base raised to the power exponent:

baseexponent

Header <tgmath.h> provides a type-generic macro version of this function.
This function is overloaded in <complex> and <valarray> (see complex pow and valarray pow).
Additional overloads are provided in this header (<cmath>) for other combinations of arithmetic types (Type1 and Type2): These overloads effectively cast its arguments to double before calculations, except if at least one of the arguments is of type long double (in which case both are casted to long double instead).

This function is also overloaded in <complex> and <valarray> (see complex pow and valarray pow).

Parameters

base
Base value.
exponent
Exponent value.

Return Value

The result of raising base to the power exponent.

If x is finite negative and y is finite but not an integer value, it causes a domain error.
if both x and y are zero, it may also cause a domain error.
If x is zero and y is negative, it may cause a domain error or an overflow range error (or none, depending on the library implementation).

If a domain error occurs, the global variable errno is set to EDOM.
If an overflow range error occurs, the global variable errno is set ERANGE.
If a domain error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to EDOM.
- And math_errhandling has MATH_ERREXCEPT set: FE_INVALID is raised.

If an overflow range error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to ERANGE.
- And math_errhandling has MATH_ERREXCEPT set: FE_OVERFLOW is raised.

Example

1
2
3
4
5
6
7
8
9
10
11
/* pow example */
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */

int main ()
{
  printf ("7 ^ 3 = %f\n", pow (7.0, 3.0) );
  printf ("4.73 ^ 12 = %f\n", pow (4.73, 12.0) );
  printf ("32.01 ^ 1.54 = %f\n", pow (32.01, 1.54) );
  return 0;
}


Output:

7 ^ 3 = 343.000000
4.73 ^ 12 = 125410439.217423
32.01 ^ 1.54 = 208.036691

See also