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

Incorrect value when using implicit multiplication #955

Closed
robinrodricks opened this issue Oct 12, 2017 · 6 comments
Closed

Incorrect value when using implicit multiplication #955

robinrodricks opened this issue Oct 12, 2017 · 6 comments

Comments

@robinrodricks
Copy link

Ok: math.eval("10000 / 10000") = 1

Fails:
math.eval("thousand = 1000");
math.eval("10 thousand / 10 thousand") = 1e+6... Huh??

I don't know if I'm doing something wrong or its a bug in math.js...

@robinrodricks
Copy link
Author

What worked was this:

(10*1000) / (10*1000) = 1 .. Ok.

But I always thought multiplication had a higher precedence than division?

@josdejong
Copy link
Owner

josdejong commented Oct 12, 2017

As far as I know, in all math applications multiplication and division have the same precedence (i.e. 4/2*2 results in 4 and not 1). How implicit multiplication is treated differs per application, in mathjs is has the same precedence as explicit multiplication.

Update: fixed a typo in the example I gave

@robinrodricks
Copy link
Author

Oh. I need some way to fix this as it appears to be a bug, like in the example I provided.

@josdejong
Copy link
Owner

josdejong commented Oct 16, 2017

This behavior is hardcoded in the expression parser, it's not configurable or something.

There are discussions though to rethink the behavior of implicit multiplication, see #792.

@robinrodricks
Copy link
Author

robinrodricks commented Oct 16, 2017 via email

@josdejong
Copy link
Owner

👍 let's close this issue and continue any discussion in #792.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants