Comments (5)
In these cases, you must use the mathematical association operator. It would look like this:
$evaluator = new \Matex\Evaluator();
$evaluator->execute('4*(3^2)'); // returns 36
$evaluator->execute('45/(3^2)'); // returns 5
from matex.
This would indeed return the correct result but it does not really solve my problem. My app uses randomly generated math expressions (which are later displayed in Latex format) so adding parenthesis where necessary would be quite a painful process.
Besides, PEDMAS is the most commonly accepted convention for the order of operation (as far as I know). I think it would be to this library's benefit to follow it.
from matex.
I think this is a pretty fundamental flaw in an expression evaluator, and agree implementing it in the package itself rather than working around it would be preferable. I'm taking a look at the source trying to understand where the order of operations is defined, but I'm having a hard time.
from matex.
If you need something much more complete to work with complex and dynamic expressions, I advise you to use this symfony component: Expression Language
https://gist.github.com/mccarlosen/ddf4b923da2a49442ae2344b850e282c
from matex.
If you need something much more complete to work with complex and dynamic expressions, I advise you to use this symfony component: Expression Language
https://gist.github.com/mccarlosen/ddf4b923da2a49442ae2344b850e282c
Thank you, that is for sure a very viable alternative, but doesn't change the fact that this is a mathematical expression evaluator, and as such it should be able to evaluate according to the standard order of operations.
from matex.
Related Issues (20)
- Code can't handle round brackets in strings
- Example given does't work
- Can't handle negative numbers HOT 1
- Rounding HOT 1
- Custom basic operators HOT 1
- Composer not installing for my PHP version. HOT 3
- Assign a value to a variable inside an expression HOT 3
- Exception: Empty argument in Evaluator->addArgument() when custom function without arguments HOT 4
- Support zero float point variables (x =>0.1)
- Problem calcul simple addition HOT 2
- Double-byte characters such as * are not available
- Could not evaluate "2*0*0.45*0.3*7.4999999999999997E-2"
- Not working with multiples of 10
- Add composer.json and add this to https://packagist.org/ HOT 7
- Make variables case sensitive (not only Lower Case) HOT 3
- Support comparison operators (>, <, =, >=,<=) to get a true / false evaluation HOT 4
- Examples difficult to understand HOT 4
- ( 101.25 + -202.44 ) results in "syntax error"
- Handle invalid operations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matex.