-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Constant expression - Power operator? #14665
Comments
Should there be e.g. square/cubic/... root and absolute value operators as well? Is power operation simply the most common one? |
@dsaf Well, yeah, it is actually common and cubic is formulated by power so power is more primitive. |
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. |
@MgSam Yeah well, this isn't really the same, there's two parts to this story, expressiveness of logic and performance, symbols are more succinct by nature and because some popular languages got it like PHP, JavaScript, F# and Python then it makes this operator fairly common. We can definitely write MathC library that got some deterministic, constant operations if and when something like Finally, I don't know how many years we will wait for something like |
This feature is already discussed at #4594. |
Disclaimer: 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:
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. :)The text was updated successfully, but these errors were encountered: