What does the `get_radix_base` function do?


#1

In the num crate, it defines a private function called get_radix_base. What is the meaning of this function?


#2

It is an internal function for to_str_radix which prints a number in given base.

Printing a binary bignum in the non-binary base b (including decimal) is quite a daunting task, and while very rudimentary, num crate uses a repeated division by some power of the base (b^k) to get the lowest k digits at a time. We want to maximize b^k as long as it does not exceed one internal digit (“limb”, a type BigDigit there) so that we can easily divide by b^k. Consequently get_radix_base(b) returns (maximal b^k, k in that case).