-
hello, I have a bigNumber math.evaluate('13^13^13') which equals this when using toString() '6.6562848475865978035230043284013443624432974644632018585795060803216352859340509223914563775799850626307341825739410338063596191955729630866847526648701580513758718046370702429572329954872213877082287662848229827685487442251981272089624869958941581489031555717609005295296211471262889459035774860004796466383927454730815865359576041260754412092609524042311516075796658957176382889961371510081659808312232799675773720753655551569016831221802339612826165349756789740927552765180516577816845778394419011207732765e+337385711567664' of course, the ToFixed() function take forever, how could I prevent the program to be stuck by a ToFixed() ? is there a reasonnable number value to check before use ToFixed() and how can I check this ? kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 |
Beta Was this translation helpful? Give feedback.
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…