pow function
Returns x to the power of exponent.
If x is an int and exponent is a non-negative int, the result is
an int, otherwise both arguments are converted to doubles first, and the
result is a double.
For integers, the power is always equal to the mathematical result of x to
the power exponent, only limited by the available memory.
For doubles, pow(x, y) handles edge cases as follows:
- if
yis zero (0.0 or -0.0), the result is always 1.0. - if
xis 1.0, the result is always 1.0. - otherwise, if either
xoryis NaN, then the result is NaN. - if
xis negative (but not -0.0) andyis a finite non-integer, the result is NaN. - if
xis Infinity andyis negative, the result is 0.0. - if
xis Infinity andyis positive, the result is Infinity. - if
xis 0.0 andyis negative, the result is Infinity. - if
xis 0.0 andyis positive, the result is 0.0. - if
xis -Infinity or -0.0 andyis an odd integer, then the result is-pow(-x ,y). - if
xis -Infinity or -0.0 andyis not an odd integer, then the result is the same aspow(-x , y). - if
yis Infinity and the absolute value ofxis less than 1, the result is 0.0. - if
yis Infinity andxis -1, the result is 1.0. - if
yis Infinity and the absolute value ofxis greater than 1, the result is Infinity. - if
yis -Infinity, the result is1/pow(x, Infinity).
This corresponds to the pow function defined in the IEEE Standard
754-2008.
Notice that the result may overflow. If integers are represented as 64-bit numbers, an integer result may be truncated, and a double result may overflow to positive or negative double.infinity.
Implementation
external num pow(num x, num exponent);