pow function
num pow(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
y
is zero (0.0 or -0.0), the result is always 1.0. - if
x
is 1.0, the result is always 1.0. - otherwise, if either
x
ory
is NaN then the result is NaN. - if
x
is negative (but not -0.0) andy
is a finite non-integer, the result is NaN. - if
x
is Infinity andy
is negative, the result is 0.0. - if
x
is Infinity andy
is positive, the result is Infinity. - if
x
is 0.0 andy
is negative, the result is Infinity. - if
x
is 0.0 andy
is positive, the result is 0.0. - if
x
is -Infinity or -0.0 andy
is an odd integer, then the result is-pow(-x ,y)
. - if
x
is -Infinity or -0.0 andy
is not an odd integer, then the result is the same aspow(-x , y)
. - if
y
is Infinity and the absolute value ofx
is less than 1, the result is 0.0. - if
y
is Infinity andx
is -1, the result is 1.0. - if
y
is Infinity and the absolute value ofx
is greater than 1, the result is Infinity. - if
y
is -Infinity, the result is1/pow(x, Infinity)
.
This corresponds to the pow
function defined in the IEEE Standard 754-2008.
Notice that an int result cannot overflow, but a double result might be double.INFINITY.
Source
external num pow(num x, num exponent);
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-math/pow.html