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

Improve efficiency of Nat::_stringify_for_base() #135

Open
saxbophone opened this issue Feb 18, 2023 · 0 comments
Open

Improve efficiency of Nat::_stringify_for_base() #135

saxbophone opened this issue Feb 18, 2023 · 0 comments
Milestone

Comments

@saxbophone
Copy link
Owner

The efficiency of this method is pretty abysmal for base-10. It can be improved somewhat by finding the largest power of 10 that will fit in uintmax_t ( $n = floor(log_{10}(uintmax)$ ) and serialising it to base $10^n$ instead.

We just need to take care to pad intermediate digits with the full number of leading zeroes, and not pad the leading digit at all.

This technique can also be used for other bases, although we might find that using bit-shifting approaches for those that are binary powers is good enough.

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

No branches or pull requests

1 participant