About `tostring_int` for bases other than 10 or 16
Hi, @user-none I've just known about your module and it works like a charm. However, I was intrigued by one aspect of the code:
ashex recurs to a local function tostring_int not accessible for the user, which in turns limits itself to base 10 and 16 (lines 602-604):
if base ~= 10 and base ~= 16 then
return nil, "base not supported"
end
Is there a specific reason not to make base conversions accessible, e.g., via a new anumber:tobase(base).
Sorry if my question is a bit dumb. I'm not (hopefully still) very familiar to bitwise operations, so maybe I'm missing something from your code. Thank you in advance.
I didn't make a generic function because there isn't much use for one. Outputting a number as a string in base 22, for example, isn't going to be widely used or needed. I limited to 10 and 16 simply because they were most common and the other projects I use this module with only need base 10 and 16.
It's certainly possible to support a tobase function and there is no technical reason it can't be done. I haven't looked at the code in awhile but for bn, in theory, all you need to do to expand out the supported bases is to expand RMAP and RRMAP. That said, the uintn type would need a bit more work because the string output is using Lua internal formatting calls.
I'm gonna look into uintn. For now I'm only using bn and for purposes which actually require arbitrary bases, so I was concerned about eventual side effects. Thanks a lot for the clarification.