Support underscores for mpz/mpq assignments from strings

Vincent Lefevre vincent at
Fri Jun 11 08:33:17 UTC 2021

On 2021-06-10 21:11:11 +0200, Hans Åberg wrote:
> The current international standard is to use as decimal separator either a period '.'or a comma ',', and as number separator spaces ' '.

But note that this is mainly for output (for humans), not to read back

> 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.

Source code still needs to be readable, understood and maintained
by humans, which is why a separator may be useful. Since the
underscore is already used as part of identifiers, it is generally
a good character to be used as the separator. But it may clash with
existing features of some languages.

> Therefore I think the support of such formats should be put into special libraries.

This means that the library would have to parse and copy the value
for GMP, something already done by GMP: see

  /* Remove spaces from the string and convert the result from ASCII to a
     byte array.  */

in mpz/set_str.c. This is a bit of a waste. IMHO, a GMP function that
accepts a byte array would be better for use by special libraries, with
their own parsing rule. Or advise to use mpn_set_str in such cases?

Vincent Lefèvre <vincent at> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

More information about the gmp-discuss mailing list