Skip to content

BigNumber too big for toFixed() but not Infinity #3239

Answered by josdejong
nycos62 asked this question in Q&A
Discussion options

You must be logged in to vote

When evaluating an arbitrary math expression there are plenty of ways to create an expression that will take forever to compute or runs out of memory. Like creating a huge matrix or so. In your example you try to create a string containing 337385711567664 characters, that will simply run out of memory (and take forever).

You can take small measures like checking how large the number is before using toFixed for example, but you will probably need many measures. The only solid solution is to run your calculations in a separate thread like a web worker, which you can kill and restart when things go wrong. See the section "Stability risks " in the following docs: https://mathjs.org/docs/expre…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nycos62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants