[bigint][math]::pow(10,22)
Gives the correct result: 10000000000000000000000
[bigint][math]::pow(10,23)
Gives an incorrect result: 100000000000000008388608
[bigint]10e23
Gives a different but also incorrect result: 999999999999999983222784
I thought that System.Numerics.biginteger worked for arbitrarily large integers?
Is there something special that needs to be done to correctly calculate arbitrarily large numbers in Powershell, or a different method that must be used instead?
The pow function takes double type arguments, and returns a double type result. Your int inputs are implicitly cast to double, and the double result is cast to bigint as best as able.
Math.Pow Method documentation
Also see this response to similar thing reported as bug. In that bug report, they suggest a function definition (including code) that will compute pow for big integer values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With