question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Constant expression - Power operator?

See original GitHub issue

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:

  1. Using left shift but this only works when raising 2 to a power.
  2. Using plain multiplications.
  3. Using Math.Pow(2, 3) or Pow(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:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
MgSamcommented, Oct 21, 2016

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.

0reactions
iam3yalcommented, Jan 20, 2017

This feature is already discussed at #4594.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found