Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I raise X to the power of Y in Powershell?

I (apparently wrongly) assumed there would be a built-in power operator or function in Powershell, but I it seems there is not, or is there?

like image 348
skeetastax Avatar asked Nov 16 '25 02:11

skeetastax


2 Answers

As you've found, real exponentation can be achieved with some accuracy by calling [Math]::Pow().

For large integer exponentiation, you might want to use [bigint]::Pow() instead:

PS ~> [Math]::Pow(256, 20)
1.4615016373309E+48
PS ~> [bigint]::Pow(256, 20)
1461501637330902918203684832716283019655932542976
like image 52
Mathias R. Jessen Avatar answered Nov 18 '25 17:11

Mathias R. Jessen


Never mind, I found the answer:

[Math]::Pow(256,3) # 256 to the power of 3 (= ~16.7 million)
like image 21
skeetastax Avatar answered Nov 18 '25 15:11

skeetastax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!