cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cmath (math.h) : pow
 
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cmath (math.h)
functions:
· acos
· asin
· atan
· atan2
· ceil
· cos
· cosh
· exp
· fabs
· floor
· fmod
· frexp
· ldexp
· log
· log10
· modf
· pow
· sin
· sinh
· sqrt
· tan
· tanh
macro constants:
· HUGE_VAL

-

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

Raise to power

Returns base raised to the power exponent:

baseexponent

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 double version of this function exists with this name.

Example

/* 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

log Compute natural logarithm (function)
exp Compute exponential function (function)
sqrt Compute square root (function)
© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us