Skip to content
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

Add exponentiation operator (**) to the Expression parser #1580

Closed
ModProg opened this issue Sep 28, 2020 · 0 comments · Fixed by godotengine/godot#58873
Closed

Add exponentiation operator (**) to the Expression parser #1580

ModProg opened this issue Sep 28, 2020 · 0 comments · Fixed by godotengine/godot#58873
Assignees
Milestone

Comments

@ModProg
Copy link

ModProg commented Sep 28, 2020

Describe the project you are working on:
A Game

Describe the problem or limitation you are having in your project:
The Expression Parser does not support ** as a pow operator. While pow(a,b) may have a better readability when used in a complex expression it is way slower to write than a**b. Especially in the case of Input fields, where the expression is lost after submitting, I don't think a lot of people will write smaller expressions more often then complex ones.
With pull request godotengine/godot#42376, this problem is increased due to commas no longer working in EditorSpinSlider.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Add ** to the operators for the Expression.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
In expression.cpp:
Add Token TK_OP_POW in _get_token and the operator switch in _parse_expression.
Add Variant OP_POW, here we need to put it between OP_NEGATE and OP_MULTIPLY i.e. increase the priority for everything >= OP_MULTIPLY by one and give OP_POW priority = 1.
In variant_op.cpp:
Add OP_POW to CASES(PREFIX), in evaluate the basic Case is obviously numbers, but at least for a**b, b ∈ ℤ most things that work for Multiplication could be adopted, this would make this more versatile than the pow function.

If this enhancement will not be used often, can it be worked around with a few lines of code
The basic version should be about 20 lines of code, implementing more functionality would increase that by a bit.

Is there a reason why this should be core and not an add-on in the asset library?:
It could not be easily done by an add-on, and it could be implemented parallel to #1045, so that both gdscript and the number input use the same syntax.

I am able to make a pull request for this, at least for a basic numbers only version.

@Calinou Calinou changed the title Add exponentiation operator (**) to Expression Parser Add exponentiation operator (**) to the Expression parser Nov 14, 2020
@akien-mga akien-mga added this to the 4.0 milestone May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants