ExpantaNum.js icon indicating copy to clipboard operation
ExpantaNum.js copied to clipboard

toStringWithDecimalPlaces throws RangeError on zero

Open Bazinga9000 opened this issue 2 years ago • 2 comments

Reproduction Steps: ExpantaNum.ZERO.toStringWithDecimalPlaces(3,true) raises the following error:

Uncaught RangeError: toFixed() digits argument must be between 0 and 100
    at Number.toFixed (<anonymous>)
    at decimalPlaces (eval at <anonymous> (test.js:102:12), <anonymous>:1213:31)
    at P.toStringWithDecimalPlaces (eval at <anonymous> (test.js:102:12), <anonymous>:1250:28)
    at <anonymous>:1:17

This works in the console on https://naruyoko.github.io/ExpantaNum.js/test.html, and also still errors when replacing 3 with any other integer.

Bazinga9000 avatar Jan 02 '23 17:01 Bazinga9000

Can reproduce the error when running new ExpantaNum(x).toStringWithDecimalPlaces(y,true), where x is any value that, after division by 10y, results in a number less than or equal to 10-100.

In particular, new ExpantaNum(1e-97).toStringWithDecimalPlaces(3,true) raises the same error, and so does new ExpantaNum(1e-96).toStringWithDecimalPlaces(4,true).

Likely a bug in the following function: https://github.com/Naruyoko/ExpantaNum.js/blob/df78659cf3b839862ee853cb41502f6033040750/ExpantaNum.js#L1207-L1212

James103 avatar Jan 02 '23 17:01 James103

α 1.4.0

Naruyoko avatar Jan 23 '23 01:01 Naruyoko