Giter VIP home page Giter VIP logo

Comments (5)

mccarlosen avatar mccarlosen commented on July 30, 2024

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.

daniel-cabane avatar daniel-cabane commented on July 30, 2024

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.

 avatar commented on July 30, 2024

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.

mccarlosen avatar mccarlosen commented on July 30, 2024

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.

 avatar commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.