问题描述
我(显然是错误的)假设 Powershell 中会有内置电源 operator
或 function
,但我似乎没有,或者有吗?
解决方法
如您所见,可以通过调用 [Math]::Pow()
以一定的精度实现实指数运算。
对于大整数取幂,您可能需要使用 [bigint]::Pow()
代替:
PS ~> [Math]::Pow(256,20)
1.4615016373309E+48
PS ~> [bigint]::Pow(256,20)
1461501637330902918203684832716283019655932542976
,
没关系,我找到了答案:
[Math]::Pow(256,3) # 256 to the power of 3 (= ~16.7 million)