-
Notifications
You must be signed in to change notification settings - Fork 475
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
Decimal.sum with large arrays exceeds the maximum call stack size #230
Comments
can you assign this issue? |
/attempt |
You can easily write your own version of function sum(array) {
return array.reduce((total, value) => total.add(value))
} |
Update: Sorry for not reading your initial issue fully before posting. It seems you're aware of what is actually the problem |
Problem
The current implementation of the Decimal.sum function requires spreading the array contents, which may lead to exceeding the maximum call stack size for large arrays. This results in a breaking point, and the function fails for arrays around 70k elements.
Expected Behaviour
The Decimal.sum function should be modified to accept an array directly, rather than relying on spreading the array contents so that large arrays can be summed.
Steps to Reproduce
Create a large array, for example:
Attempt to use Decimal.sum with the large array:
Environment
decimal.js: ^10.4.3
Node.js version: v18.17.1
TypeScript version: 5.2.2
The text was updated successfully, but these errors were encountered: