Proposal: Constant expression - Power operator?
See original GitHub issueDisclaimer: I don’t know if it’s worthy of a proposal but it’s really a tiny feature and some people might have some interest in it.
Currently, there are three ways to raise a number to a power:
- Using left shift but this only works when raising 2 to a power.
- Using plain multiplications.
- Using
Math.Pow(2, 3)
orPow(2, 3)
but it’s not a constant expression.
So what I’m proposing is a power operator much like it exists in Python or JavaScript **
but this one will be evaluated at compile time unless it can’t because the base or the power are non-constant.
The motivation for this is mainly to allow us represent some formulas in their natural/symbolic/mathematical way, I wish we could have constexpr
in C# but this is another story. 😃
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Proposal: Exponentiation operator · Issue #2585
In the Symbolism computer algebra library, + , * , / , and - are overloaded to create Sum , Product , Quotient...
Read more >constexpr Operator
The constexpr Operator I propose a new operator invoked as constexpr() . It evaluates to true when invoked in a context that requires...
Read more >c# - How to do exponentiation in constant expression?
Having used the exponent operator ^ in the initialisation of a VB class's public constant following this question.
Read more >Expression Constants, Operators, and Functions
An expression is a string that evaluates some value. ... The tables below contain constants, operators, and functions you can use in ...
Read more >Compile-Time Constant Expressions for Swift - Pitches
Chris Lattner and I have been working on a proposal to add compile-time constant expressions to Swift. Our goal is to create a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems to me like people ask about this kind of stuff a lot- evaluate math at compile time, strings at compile time. Seems like a general purpose feature that allowed running statically known values through static methods at compile time would be a better idea.
This feature is already discussed at #4594.