Support underscores for mpz/mpq assignments from strings

Anders Andersson pipatron at gmail.com
Thu Jun 10 22:19:40 UTC 2021


On Thu, Jun 10, 2021 at 7:59 PM Marc Glisse <marc.glisse at inria.fr> wrote:
>
> 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 think this is the right way to think about this. This would be
purely for source code formatting, not for standardization and user
output. If you're going to follow a standard it makes more sense to
follow what everyone else is doing and an overwhelming majority seems
to have gone with the "underscore" route - the main (only?) outlier
being C++ which you already mentioned. Java, Perl, Python, C#, Ada,
Haskell, Rust, Go, they all use an underscore.


More information about the gmp-discuss mailing list