Skip to content
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

RFC: parseBase/toString for radixes outside 2/10/16 (maybe even 8) #107

Closed
axic opened this issue Jan 24, 2016 · 5 comments
Closed

RFC: parseBase/toString for radixes outside 2/10/16 (maybe even 8) #107

axic opened this issue Jan 24, 2016 · 5 comments

Comments

@axic
Copy link
Contributor

axic commented Jan 24, 2016

Does any other base than 2/10/16 (and maybe even 8) make any sense in day to day usage? Is there any use case for them today? The current implementation forces a single hardcoded alphabet consisting of 0-9,a-z,A-Z cut off at the radix.

Wouldn't it make more sense for those to support a user-supplied alphabet, similarly to the way base-x does it?

@indutny
Copy link
Owner

indutny commented Jan 24, 2016

I think it should probably work for any bases from 1 to 36 as for regular JS numbers.

@indutny
Copy link
Owner

indutny commented Jan 24, 2016

IMO, user supplied alphabet does not make sense, never heard about this sort of API in any serious big number library.

@axic
Copy link
Contributor Author

axic commented Jan 24, 2016

I assume you are aware that the alphabet varies between big number libraries.

gmp (used by node-bigint):

For base in the range 2..36, digits and lower-case letters are used; for -2..-36, digits and upper-case letters are used; for 37..62, digits, upper-case letters, and lower-case letters (in that significance order) are used.

openssl (used by node-bignum aka bignum):
parser only supports base 2, 10 and 16, and toString only supports 10 and 16

bignumber.js:

For bases from 10 to 36, lower and/or upper case letters can be used to represent values from 10 to 35.
For bases above 36, a-z represents values from 10 to 35, A-Z from 36 to 61, and $ and _ represent 62 and 63 respectively (this can be changed by editing the ALPHABET variable near the top of the source file).

sjcl:
only supports base 2, 10, 16, 32, 64. Base 64 is the well known base64 alphabet. Base 32:

The encoding alphabet for sjcl.codec.base32 now matches that specified by the RFC 4648, rather than the extended hex alphabet.

bn.js:
compared to the above, given that bn.js is limited to <= base-36, the alphabet usage matches that of bignumber.js

@indutny
Copy link
Owner

indutny commented Jan 27, 2016

Ok, I was a bit wrong then. Anyway, I don't feel like it is justified. Performance-wise it will mean a lot slower code. 3rd-party libraries could take toArray output and convert it to requested base if needed.

@indutny
Copy link
Owner

indutny commented Jan 27, 2016

Sorry, closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants