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

parser considers array indexes as one-based #475

Closed
simoneb opened this issue Oct 2, 2015 · 3 comments
Closed

parser considers array indexes as one-based #475

simoneb opened this issue Oct 2, 2015 · 3 comments

Comments

@simoneb
Copy link

simoneb commented Oct 2, 2015

Hello,

With this setup:

var parser = math.parser();
parser.set('a', [1,2,3]);

I'm trying to figure out why this is happening:

parser.get('a')[0];   
// 1
parser.eval('a[0]'); 
// IndexError {index: 0, min: 1, max: NaN, message: "Index out of range (0 < 1)"}

Searching past issues I see that #23 mentions that indexes should be zero-based, but apparently they aren't.

@simoneb simoneb changed the title parser condider array indexes as zero-based parser condider array indexes as one-based Oct 2, 2015
@simoneb simoneb changed the title parser condider array indexes as one-based parser considers array indexes as one-based Oct 2, 2015
@josdejong
Copy link
Owner

Yes this can be confusing. The expression parser uses one-based indices with upper bound included, whilst the JavaScript methods use zero-based indices with upper bound excluded. The differences between JavaScript API and expression parser are summarized here: http://mathjs.org/docs/expressions/syntax.html#differences-from-javascript

See also #66.

@simoneb
Copy link
Author

simoneb commented Oct 2, 2015

Ahh, I had been looking for this but couldn't find it. Thanks

@simoneb simoneb closed this as completed Oct 2, 2015
@josdejong
Copy link
Owner

You're welcome :)

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