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:
const bigArray: number[] = Array.from({ length: 100e3 }).fill(1) as number[];
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