cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
370 stars 45 forks source link

9/6/3 is not correct #147

Closed rwmorton closed 7 months ago

rwmorton commented 7 months ago

I believe this is a bug. Evaluating the expression 9/6/3 should be 0.5. When you paste that into the demo on the compute engine page it spits out 4.5. The problem is that each / symbol appears to be inserting a fraction but it should really be evaluated as an operator in the order in which they appear. Hope that makes sense?

image

arnog commented 7 months ago

The precedence of operators and how they should be interpreted is a matter of convention. There is no "right" or "wrong" way.

That said, the convention that the Compute Engine uses by default is that division operators, such as / are left-associative. Unfortunately, due to a bug, the associativity of operators was not applied correctly. This has now been fixed.