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

Cannot index Array/Matrix with bigint #3360

Closed
gwhitney opened this issue Jan 26, 2025 · 0 comments · Fixed by #3361
Closed

Cannot index Array/Matrix with bigint #3360

gwhitney opened this issue Jan 26, 2025 · 0 comments · Fixed by #3361
Labels
category:expressions Issues about the expression parser, variable scoping etc.

Comments

@gwhitney
Copy link
Collaborator

Describe the bug
A bigint value is rejected as an Array or Matrix index in mathjs expressions. This ban is particularly onerous when the number default is bigint.

To Reproduce

const math = create(all, {number: 'bigint'}
console.log(math.evaluate('[4,5,6][2]')

Rather than logging 5n, this throws an error with message TypeError: Dimension must be an Array, Matrix, number, string, or Range

Discussion
While I understand that JavaScript does not allow bigint array indices, the mathjs expression language aspires to mathematical accuracy and logic. From such a perspective, there is no reason to disparage bigint indices; in fact, they are in some sense more natural, as array/matrix indices must be integers, and bigints only represent integers. Furthermore, when doing high-precision integer arithmetic, the {number: 'bigint'} configuration is very useful, but it is currently practically very cumbersome to use because of the need to convert indices to number explicitly.

Recommendation
Indexing with bigints be supported. Unless there is any objection, I will develop a PR to this effect.

@gwhitney gwhitney added the category:expressions Issues about the expression parser, variable scoping etc. label Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:expressions Issues about the expression parser, variable scoping etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant