Support underscores for mpz/mpq assignments from strings
haberg-1 at telia.com
Thu Jun 10 19:11:11 UTC 2021
> On 10 Jun 2021, at 19:58, 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:
>> Some projects add workarounds for the gmp to allow this syntax, e.g.:
>> 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.
The current international standard is to use as decimal separator either a period '.'or a comma ',', and as number separator spaces ' '.
However, in a computer context, for writing code, for example the list [1,2,3,4] then becomes the same as [1.2, 3.4], which is not likely what was intended. Therefore I think the support of such formats should be put into special libraries.
More information about the gmp-discuss