I've created a script to divide numbers with the chosen number of decimal places. Everything works fine unless I set a huge number of decimal places. The file run via Node.js gives up when the decimal numbers array length reaches ~2400, Chrome gives up on ~1900.
I simplified my code and the script sample below throws Maximum call stack size exceeded
RangeError up on ~20000
decimal numbers array length. I thought that this Error throws when the loop or recursive function is called endlessly, but in my case there is a countable number of iterations. It may be a huge number but my module is intended to do the math operations on big numbers.
Why does it happen and Can I avoid this RangeError to occur?
var decimals = [];
var max = 20000;
recurse();
function recurse() {
decimals.push(Math.floor(Math.random()*10));
if(decimals.length === max) return;
recurse();
}