|
|
|
Defined in header <math.h> | ||
float powf(float base,float exponent); | (1) | (since C99) |
double pow(double base,double exponent); | (2) | |
longdouble powl(longdouble base,longdouble exponent); | (3) | (since C99) |
Defined in header <tgmath.h> | ||
#define pow( base, exponent ) | (4) | (since C99) |
powl
is called. Otherwise, if any argument has integer type or has typedouble,pow
is called. Otherwise,powf
is called. If at least one argument is complex or imaginary, then the macro invokes the corresponding complex function (cpowf,cpow,cpowl).Contents |
base | - | base as floating-point value |
exponent | - | exponent as floating-point value |
If no errors occur,base raised to the power ofexponent (baseexponent
) is returned.
If a domain error occurs, an implementation-defined value is returned (NaN where supported).
If a pole error or a range error due to overflow occurs,±HUGE_VAL,±HUGE_VALF
, or±HUGE_VALL
is returned.
If a range error occurs due to underflow, the correct result (after rounding) is returned.
Errors are reported as specified inmath_errhandling
.
Ifbase is finite and negative andexponent is finite and non-integer, a domain error occurs and a range error may occur.
Ifbase is zero andexponent is zero, a domain error may occur.
Ifbase is zero andexponent is negative, a domain error or a pole error may occur.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
+∞
and raisesFE_DIVBYZERO-∞
and raisesFE_DIVBYZERONaN
NaN
NaN
and raisesFE_INVALID ifbase is finite and negative andexponent is finite and non-integer.|base|<1
|base|>1
|base|<1
|base|>1
Althoughpow
cannot be used to obtain a root of a negative number,cbrt is provided for the common case whereexponent
is1/3.
#include <errno.h>#include <fenv.h>#include <math.h>#include <stdio.h>// #pragma STDC FENV_ACCESS ON int main(void){// typical usageprintf("pow(2, 10) = %f\n", pow(2,10));printf("pow(2, 0.5) = %f\n", pow(2,0.5));printf("pow(-2, -3) = %f\n", pow(-2,-3)); // special valuesprintf("pow(-1, NAN) = %f\n", pow(-1, NAN));printf("pow(+1, NAN) = %f\n", pow(+1, NAN));printf("pow(INFINITY, 2) = %f\n", pow(INFINITY,2));printf("pow(INFINITY, -1) = %f\n", pow(INFINITY,-1)); // error handlingerrno=0;feclearexcept(FE_ALL_EXCEPT);printf("pow(-1, 1/3) = %f\n", pow(-1,1.0/3));if(errno==EDOM)perror(" errno == EDOM");if(fetestexcept(FE_INVALID))puts(" FE_INVALID raised"); feclearexcept(FE_ALL_EXCEPT);printf("pow(-0, -3) = %f\n", pow(-0.0,-3));if(fetestexcept(FE_DIVBYZERO))puts(" FE_DIVBYZERO raised");}
Possible output:
pow(2, 10) = 1024.000000pow(2, 0.5) = 1.414214pow(-2, -3) = -0.125000pow(-1, NAN) = nanpow(+1, NAN) = 1.000000pow(INFINITY, 2) = infpow(INFINITY, -1) = 0.000000pow(-1, 1/3) = -nan errno == EDOM: Numerical argument out of domain FE_INVALID raisedpow(-0, -3) = -inf FE_DIVBYZERO raised
(C99)(C99) | computes square root (\(\small{\sqrt{x} }\)√x) (function)[edit] |
(C99)(C99)(C99) | computes cube root (\(\small{\sqrt[3]{x} }\)3√x) (function)[edit] |
(C99)(C99)(C99) | computes square root of the sum of the squares of two given numbers (\(\scriptsize{\sqrt{x^2+y^2} }\)√x2 +y2 ) (function)[edit] |
(C99)(C99)(C99) | computes the complex power function (function)[edit] |
C++ documentation forpow |