question on fixing the mpz_sizeinbase()

marco.bodrato at tutanota.com marco.bodrato at tutanota.com
Sun Mar 17 20:13:32 CET 2024


Ciao,

I answer here to a question from gmp-discuss.

17 mar 2024, 01:28 da tg at gmplib.org:

> "website.reader" <website.reader at protonmail.com> writes:
>
>  Here's the suggested fix for this command in a C++ code unit
>
This question arises once every couple of years, more or less...
Should we write a new mpz_sizeinbase_exactbutpossiblymuchslower() function?

Ideas:
 - use the vlog[] table we already have in mpn/generic/rootrem.c to compute some "decimal digits" of the logarithm base 2 of the number to more exactly discriminate within the "digits" and the "digits+1" case based on the higher bits of the number. This keeps on being O(1) but should narrow the range of cases where we need to
( - compute a sort of ui_powhi_ui  (we will have a use for mulhi :-), or finally)
 - compute ui_pow_ui and fully compare, giving the exact result.

Do you feel it may be useful? It would be more clever than what the user can simply do themself.
Ĝis,
mb


More information about the gmp-devel mailing list