Closed trbrc closed 2 years ago
Yes.
The problem is that I want to keep BigNumber creation as fast as possible when a base argument of 10 is passed to the constructor, because many users include it as a matter of course.
Currently, a time-consuming base conversion is avoided (and exponential notation is also accepted) using
// Allow exponential notation to be used with base 10 argument, while
// also rounding to DECIMAL_PLACES as with other bases.
if (b == 10) {
x = new BigNumber(v);
return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
}
Yes, I could change that to
if (b == 10 && ALPHABET.slice(0, 10) === '0123456789') {
but I don't want to add further code to a very hot path in the constructor just to cover a case which nobody probably uses.
I may just make it explicit in the documentation that that first 10 characters of the alphabet are hard-coded to '0123456789'
for base 10.
Yes, I could change that to
if (b == 10 && ALPHABET.slice(0, 10) === '0123456789') {
but I don't want to add further code to a very hot path in the constructor just to cover a case which nobody probably uses.
Could it do this check once when a new ALPHABET
is set from config
, and just use a boolean flag here?
Just adding it to the documentation would work OK as well. On the other hand, since it is possible to opt out by not specifying the base, wouldn't it be better to fix it and document the performance implications instead?
Could it do this check once when a new ALPHABET is set from config, and just use a boolean flag here?
Yes, I'll consider it.
Fixed in v9.0.2. Thanks for your input.
ALPHABET
appears to be hardcoded to'0123456789'
when the base is 10.Log: