POW 3CW "09 March 2006" "mathcw-1.00"

Table of contents


NAME

powf, pow, powl, poww, powq, powll, powdf, powd, powdl, powdll - power function

SYNOPSIS

cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ]

#include <mathcw.h>

extern float powf (float x, float y);

extern double pow (double x, double y);

extern long double powl (long double x, long double y);

extern __float80 poww (__float80 x, __float80 y);

extern __float128 powq (__float128 x, __float128 y);

extern long_long_double powll (long_long_double x, long_long_double y);

extern decimal_float powdf (decimal_float x, decimal_float y);

extern decimal_double powd (decimal_double x, decimal_double y);

extern decimal_long_double powdl (decimal_long_double x, decimal_long_double y);

extern decimal_long_long_double powdll (decimal_long_long_double x, decimal_long_long_double y);

NB: Functions with prototypes containing underscores in type names may be available only with certain extended compilers.


DESCRIPTION

Compute the first argument raised to the power of the second argument.

Caution: The mathematical equivalence pow(x,y) == exp(y * log(x)) might appear to make the power functions superfluous. However, it does not provide a computationally-acceptable path to the power functions, and use of the exponential and logarithm function for computing the power function can lead to severe, and unavoidable, accuracy loss. An accurate implementation of the power function is much more complex than almost all of the elementary functions.

Thus, when you need a power, use pow(x,y) directly, except in the special case when the first argument is the floating-point base (usually 2, sometimes 10 or 16), and the second argument is an integral value representable in type int, for which ldexp(2.0,(int)y) or ldexpd(10.DD,(int)y) are faster, and guaranteed to be exact. Internally, the mathcw library implementation of pow(x,y) guarantee exact results for arguments of 0, 1, Infinity, NaN, and an initial argument of the base. Other implementations may behave differently.


RETURN VALUES

Return x**y.

Important special cases of pow(x,y) that are mandated by the C99 Standard are summarized in this table:


-------------------------------------------------------------------
x \ y |    -0    +0    -1    +1  -Inf  +Inf -QNaN +QNaN -SNaN +SNaN
-------------------------------------------------------------------
   -0 |    +1    +1  -Inf    -0  +Inf    +0 -QNaN +QNaN -SNaN +SNaN
   +0 |    +1    +1  +Inf    +0  +Inf    +0 -QNaN +QNaN -SNaN +SNaN
   -1 |    +1    +1    -1    -1    +1    +1 -QNaN +QNaN -SNaN +SNaN
   +1 |    +1    +1    +1    +1    +1    +1    +1    +1    +1    +1
 -Inf |    +1    +1    -0  -Inf    +0  +Inf -QNaN +QNaN -SNaN +SNaN
 +Inf |    +1    +1    +0  +Inf    +0  +Inf -QNaN +QNaN -SNaN +SNaN
-QNaN |    +1    +1 -QNaN -QNaN -QNaN -QNaN -QNaN +QNaN -SNaN +SNaN
+QNaN |    +1    +1 +QNaN +QNaN +QNaN +QNaN -QNaN +QNaN -SNaN +SNaN
-SNaN |    +1    +1 -SNaN -SNaN -SNaN -SNaN -QNaN +QNaN -SNaN +SNaN
+SNaN |    +1    +1 +SNaN +SNaN +SNaN +SNaN -QNaN +QNaN -SNaN +SNaN
-------------------------------------------------------------------
Notice in particular that C99 requires that pow(+/-0,NaN) = 1, pow(NaN,+/-0) = 1, and pow(1,NaN) = 1, violating the general practice of IEEE 754 arithmetic that NaN arguments of numeric operations and functions produce NaN results.

ERRORS

Apart from the special cases noted earlier, if the second argument is a NaN, or the first argument is a NaN, set errno to EDOM and return the NaN argument. If the result is too big to represent, return an Infinity of the appropriate sign and set errno to ERANGE. If both arguments are zero, return +1.

Although 0**0 is mathematically undefined, it is often programmatically convenient to have the rule that 0**finite and 0**infinite are always 1, and most C library implementations behave that way, even though the C89 and C99 Standards allow 0**0 to be treated as an error.


SEE ALSO

exp(3CW), expm1(3CW), exp2(3CW), exp2m1(3CW), exp8(3CW), exp8m1(3CW), exp10(3CW), exp10m1(3CW), exp16(3CW), exp16m1(3CW), ipow(3CW), log(3CW), log1p(3CW), log2(3CW), log21p(3CW), log8(3CW), log81p(3CW), log10(3CW), log101p(3CW), log16(3CW), log161p(3CW).