Support underscores for mpz/mpq assignments from strings
Marc Glisse
marc.glisse at inria.fr
Thu Jun 10 17:58:32 UTC 2021
On Thu, 10 Jun 2021, Sergey B Kirpichev wrote:
> a common feature of modern languages is using underscores as visual
> separators for digit grouping purposes in integral, floating-point and
> complex number literals, see:
> https://www.python.org/dev/peps/pep-0515/
>
> Some projects add workarounds for the gmp to allow this syntax, e.g.:
> https://github.com/ocaml/Zarith/pull/75
>
> I think, the gmp can accept this syntax. Tentative patch attached.
There is nothing special about the underscore, English uses ',', French
uses '.', some use a space, C++ seems to go for "'", etc.
C locales have thousands_sep (and grouping), similar to decimal_point,
although I don't think we support it, and it only seems allowed before the
decimal point, strangely enough.
If we add support for separators, we need to do it in a way that allows
the user the specify the separator, either through the locale or through
an argument.
I don't know if mpz_inp_str is the right function to introduce this, I
would expect to see it in gmp_*scanf first, but others would know better.
--
Marc Glisse
More information about the gmp-discuss
mailing list