Support underscores for mpz/mpq assignments from strings
Hans Åberg
haberg-1 at telia.com
Mon Jun 14 18:59:27 UTC 2021
> On 14 Jun 2021, at 19:43, Marco Bodrato <bodrato at mail.dm.unipi.it> wrote:
>
> 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?
For rational numbers, there are the following character classes involved: ignored, plus, minus, digit, quotient. Then the lexing might proceed by discarding the characters in the ignored character class, and for the remaining part, follow this grammar (ε is the empty string)
sign ≔ plus|minus|ε
number ≔ digit+
integer ≔ sign number
rational ≔ integer quotient integer
More information about the gmp-discuss
mailing list