You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suggestion: implement an exponentiation (power-of) operator #3603
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugResolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.WG-Languageparser, language semantics
C# doesn't have it, so does PowerShell really need it?
The operator isn't used all that often, especially in typical PowerShell scripts
I can't speak to the real-world need, only that I keep missing it personally. Perhaps others can comment.
Frankly, I find the absence of an exponentiation operator from C# puzzling; this blog post from 2004 explains that it wasn't included because it is "fairly rare", which wasn't too well-received in the comments.
Aside from that, PowerShell already has operators that C# doesn't have, and it is a sufficiently different beast so that I wouldn't rule it out just based on that.
Perhaps PowerShell can lead by example and down the road we'll see an operator added to C# as well? :)
An operator is potentially confusing - different languages use different tokens (is it ** or ^)
**, by contrast, while not used by all languages, seems to have no other meaning, and, as stated, is used in several popular languages: Python, Ruby, JavaScript, Perl
[Math]::Pow(2, 8) is really readable.
It is readable, but neither easy to remember nor to type.
To me, a dedicated exponentiation operator seems like a natural complement to the arithmetic operators.
I have missed the Python ** power operator as well, sometimes. Adding a suggestion that this operator could be in the form:
2 -pow 8
Which is perhaps more clear, more discoverable, and inviting less confusion than ^ or **. That would be different to the arithmetic syntax (+, -, *, /), but consistent with -shl syntax.
PowerShell tends to like full words, so 2 -power 8 is another option, but -pow has the advantage of matching the name of [math]::Pow()
My personal opinion is that I would be fine adding a power operator. It would certainly not be high on my priority list, but since Xavier Hahn (@Gimly) is already offering to contribute the work, I don't see any major downside to enabling this capability. For the syntax, I think I prefer 2 -pow 8 only because it enables adding more operators in the future without running out of symbols or remember what which ones means what.
Reacted by Michael Klement and Rain Sallow (/u/ta11ow)
I dunno about using -pow. If we went this way, I'd expect the modulo operator to be -mod but instead it is %. I don't see a strong need for this operator but if it gets implemented, I'd prefer syntax inline with Python and JavaScript (**) given that there is no equivalent operator in C#.
One other option is to consider doing what C# did to allow folks to use "simpler" method invocations e.g.: pow(), sin(), cos() etc. C# does this by allowing users to add a using static System.Math.
Reacted by Mark Kraus, Michael Klement and Alexandre H.T.R. Bonfitto
using static definitely sounds like an interesting addition worth exploring separately, but it doesn't directly address what was proposed here: something that's available as built-in functionality, preferably as an operator.
(Making the static members of [math] available by default would be problematic, given that it contains such generically named members such as Log).
I've been following this one on the periphery, so I might as well chime in.
I'm not sure how useful a native power operator in PowerShell really is. I believe anyone who is using it would also be using the other Math statics already and I definitely don't see a need to add those as native operators. I like the use static idea, so long as it can be implemented at the user's discretion for the reason of Michael Klement (@mklement0) point about Log().
If use static were introduced as a user discretion feature, it may be confusing if this also couldn't be used on user defined PowerShell classes.
I still would find it usefull. pwsh has nice numbers (like python/lisp). and cannot use fsharp for as it is too typed. but for simple and small formulas in console it is great. so having 2.pow(512) or 2**512 would be great.
Most programming languages have an exponentiation operator.
It's odd that Powershell does not have one, considering it's fairly powerful.
I was trying to convert a number in bytes to TB, and i assumed that $MyVariable/(1024^4) would work. That's when i realized that Powershell doesn't have any exponentiation operator. Fortunately, i could substitute that by $MyVariable/1TB , but what if you need exponentiation for other uses?
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugResolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.WG-Languageparser, language semantics
Activity
lzybkr commentedon Apr 20, 2017
I'm disinclined to support this operator. My thinking:
**or^)[Math]::Pow(2, 8)is really readable.mklement0 commentedon Apr 20, 2017
Thanks for the feedback.
I can't speak to the real-world need, only that I keep missing it personally. Perhaps others can comment.
Frankly, I find the absence of an exponentiation operator from C# puzzling; this blog post from 2004 explains that it wasn't included because it is "fairly rare", which wasn't too well-received in the comments.
Aside from that, PowerShell already has operators that C# doesn't have, and it is a sufficiently different beast so that I wouldn't rule it out just based on that.
Perhaps PowerShell can lead by example and down the road we'll see an operator added to C# as well? :)
^indeed invites confusion, because it has different semantics in some languages.**, by contrast, while not used by all languages, seems to have no other meaning, and, as stated, is used in several popular languages: Python, Ruby, JavaScript, PerlIt is readable, but neither easy to remember nor to type.
To me, a dedicated exponentiation operator seems like a natural complement to the arithmetic operators.
HumanEquivalentUnit commentedon Sep 1, 2017
I have missed the Python
**power operator as well, sometimes. Adding a suggestion that this operator could be in the form:Which is perhaps more clear, more discoverable, and inviting less confusion than
^or**. That would be different to the arithmetic syntax (+,-,*,/), but consistent with-shlsyntax.PowerShell tends to like full words, so
2 -power 8is another option, but-powhas the advantage of matching the name of[math]::Pow()mklement0 commentedon Sep 1, 2017
HumanEquivalentUnit:
I can see both sides of the argument, and I'd be happy with either syntax.
Added token for power of operator
SteveL-MSFT commentedon Oct 11, 2017
My personal opinion is that I would be fine adding a power operator. It would certainly not be high on my priority list, but since Xavier Hahn (@Gimly) is already offering to contribute the work, I don't see any major downside to enabling this capability. For the syntax, I think I prefer
2 -pow 8only because it enables adding more operators in the future without running out of symbols or remember what which ones means what.rkeithhill commentedon Oct 11, 2017
I dunno about using
-pow. If we went this way, I'd expect the modulo operator to be-modbut instead it is%. I don't see a strong need for this operator but if it gets implemented, I'd prefer syntax inline with Python and JavaScript (**) given that there is no equivalent operator in C#.One other option is to consider doing what C# did to allow folks to use "simpler" method invocations e.g.:
pow(),sin(),cos()etc. C# does this by allowing users to add ausing static System.Math.SteveL-MSFT commentedon Oct 11, 2017
using staticmight be a better general solution that works well with the math functionsiSazonov commentedon Oct 11, 2017
I vote for
using static- it looks very power. We need to explore this deeper.iSazonov commentedon Oct 12, 2017
Steve Lee (@SteveL-MSFT) I thinnk we should close the Issue. If we want
discuss/implement staticit is better open new Issue.mklement0 commentedon Oct 12, 2017
using staticdefinitely sounds like an interesting addition worth exploring separately, but it doesn't directly address what was proposed here: something that's available as built-in functionality, preferably as an operator.(Making the static members of
[math]available by default would be problematic, given that it contains such generically named members such asLog).markekraus commentedon Oct 12, 2017
I've been following this one on the periphery, so I might as well chime in.
I'm not sure how useful a native power operator in PowerShell really is. I believe anyone who is using it would also be using the other
Mathstatics already and I definitely don't see a need to add those as native operators. I like theuse staticidea, so long as it can be implemented at the user's discretion for the reason of Michael Klement (@mklement0) point aboutLog().If
use staticwere introduced as a user discretion feature, it may be confusing if this also couldn't be used on user defined PowerShell classes.iSazonov commentedon Oct 12, 2017
Where is Issue for
use static? :-)markekraus commentedon Oct 12, 2017
Opened #5099 for discussion/tracking of
use staticdzmitry-lahoda commentedon Feb 3, 2022
I still would find it usefull. pwsh has nice numbers (like python/lisp). and cannot use fsharp for as it is too typed. but for simple and small formulas in console it is great. so having 2.pow(512) or 2**512 would be great.
rapettif commentedon Aug 21, 2024
Most programming languages have an exponentiation operator.
It's odd that Powershell does not have one, considering it's fairly powerful.
I was trying to convert a number in bytes to TB, and i assumed that $MyVariable/(1024^4) would work. That's when i realized that Powershell doesn't have any exponentiation operator. Fortunately, i could substitute that by $MyVariable/1TB , but what if you need exponentiation for other uses?
alexandrehtrb commentedon Aug 26, 2025
+1 for this
2**4is better than[Math]::Pow(2,4)