1
我想知道,因为当我在检查模式下运行我的代码时,似乎有一些差异。例如:x.pow(n)和pow(x,n)之间的区别是什么?
List<List> getFactors(int n)
{
List<List> factors = [[1, n]];
double top = pow(n,1/2);
int test = 2;
while (test <= top)
{
if (n % test == 0)
factors.add([test, n ~/ test]);
test++;
}
return factors;
}
工作原理是,但是当我改变pow(n,1/2)
到n.pow(1/2)
它返回检查模式错误。唯一的解决办法是将n
的类型更改为双倍。为什么是这样?两者之间的一般差异也很好理解。谢谢!
我不认为int,num或double有pow方法,只有Math.pow()。 http://api.dartlang.org/docs/releases/latest/dart_math.html#pow http://api.dartlang.org/docs/releases/latest/dart_core/num.html – 2013-04-29 01:07:45
我知道它没有列在api引用,但可以尝试像'print(9.pow(2));'并且它可以工作。 – CopOnTheRun 2013-04-29 02:21:06