pow


function
     double pow (      double base,      double exponent );
long double pow ( long double base, long double exponent );
      float pow (       float base,       float exponent );
     double pow (      double base,         int exponent );
long double pow ( long double base,         int exponent );

Raise to power

Returns base raised to the power exponent:

baseexponent

In C++, this function is overloaded in <complex> and <valarray> (see complex pow and valarray pow).

Parameters

base
Floating point value.
exponent
Floating point value.


Return Value

The result of raising base to the power exponent.

If the magnitude of the result is so large that it cannot be represented in an object of the return type, a range error occurs, returning HUGE_VAL with the appropiate sign and setting the value of the global variable errno to the ERANGE value.

If base is negative and exponent is not an integral value, or if base is zero and exponent is negative, a domain error occurs, setting the global variable errno to the value EDOM.

Portability

In C, only the version taking two double parameters exists with this name. The other overloads are only available in C++.

Example

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

int main ()
{
  printf ("7 ^ 3 = %lf\n", pow (7,3));
  printf ("4.73 ^ 12 = %lf\n", pow (4.73,12));
  printf ("32.01 ^ 1.54 = %lf\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