Eval math operations
See original GitHub issueWe need to add a tool to eval pure math and bool operations.
For example, we can check that 1 + 2
is 3
and "a" * 2
is "aa"
We need it because sometimes we restrict to use several datatypes in some places: like float
in dict keys. But, people can actually write float
numbers as math expressions: 0.1 + 5 * 10 ^ 2
. We have to parse this information and return result nodes.
Algorithm:
- if all elements are constants - return the evaluated result
- if anything fails - return the wrapping node itself
Refs #861
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (13 by maintainers)
Top Results From Across the Web
Expression Evaluation with Basic Operations - CK12-Foundation
To evaluate a variable expression means to find the value of the expression for given values of the variables. To evaluate, substitute the...
Read more >php - calculate math expression from a string using eval
It must contain at least two operands and an operator. Operands' name could be in upper or lower case. By now, math functions...
Read more >Arithmetic Expression Evaluation - GeeksforGeeks
Arithmetic Expression Evaluation · Convert the expression in Reverse Polish notation( post-fix notation). · Push the operands into the stack in ...
Read more >Python eval(): Evaluate Expressions Dynamically - Real Python
Python's eval() allows you to evaluate arbitrary Python expressions from a string-based or compiled-code-based input. This function can be handy when you're ...
Read more >eval() - JavaScript - MDN Web Docs - Mozilla
The eval() function evaluates JavaScript code represented as a string and returns its completion value. The source is parsed as a script.
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 FreeTop 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
Top GitHub Comments
Sounds like a good idea. Let’s try it!
It is a complicated subject. People usually do not code such operations, but in certain situations it makes the code clearer. For example, if you want a variable to hold an amount of days in seconds, you could write
days = x*24*60*60
. There are constant operations, but you can clearly see what is stored in this variable.I suppose I could explore the usage of some of the modules in the project for the purpose of auto improving the code, and use
noqa
s in the cases in which the user would not want the code to be modified.