Support underscores for mpz/mpq assignments from strings

Marco Bodrato bodrato at
Mon Jun 14 17:43:30 UTC 2021

Il 2021-06-14 18:53 Marc Glisse ha scritto:
> On Mon, 14 Jun 2021, Marco Bodrato wrote:
>> Would you suggest to document the two exceptions, or to change the 
>> code for a strict ignore-everywhere policy?
> I vaguely remember past discussions that seemed to go in the reverse
> direction: change the code to stop ignoring spaces in the middle of a
> number...

Yes, you are probably right!

And in past discussions, also some other features was requested...

Eg, in the code for mpq_set_str we have:
/* FIXME: Would like an mpz_set_mem (or similar) accepting a pointer and
    length so we wouldn't have to copy the numerator just to 
    it.  */

We might add such a mpz_set_mem function, requiring an explicit base and 
ignoring any char that is not a digit for that base.
This should allow the maximal flexibility for any caller, that can check 
the syntax with its own criteria, and should never need to copy: not to 
remove/convert separators, not to null-terminate, not at all.
It can not detect/return "error", of course, except "base out of range".

In case, the question would be, what about mpq and mpf? Should we add a 
mpq_set_memmem that leave to the caller the work of searching for "/" 
and mpf_set_memmemmem with already split integer/fractional/exponent 
parts, with possibly empty ones?


More information about the gmp-discuss mailing list