Support underscores for mpz/mpq assignments from strings
Hans Åberg
haberg-1 at telia.com
Mon Jun 14 16:31:06 UTC 2021
> On 14 Jun 2021, at 15:51, Vincent Lefevre <vincent at vinc17.net> wrote:
>
> On 2021-06-14 14:50:43 +0200, Hans Åberg wrote:
>>
>>> On 14 Jun 2021, at 10:59, Vincent Lefevre <vincent at vinc17.net> wrote:
>>>
>>> On 2021-06-11 18:20:01 +0200, Hans Åberg wrote:
>>>> But you can probably cannot change mpz_set_str,
>>>> because it is modelled on C behavior.
>>>
>>> It isn't. In C, whitespace isn't a separator.
>>
>> The GMP manual, sec. 5.2, is not clear on this, as it says that whitespace is discarded, whereas in C/C++ it is only the initial whitespace.
>
> I think that the GMP manual is clear: mpz_set_str ignores whitespace
> anywhere in the string (contrary to C's strtod, etc.).
Then perhaps it is OK to add it to ignore '_' as well: In C/C++ I think the idea is that one should be able to pick up a sequence of numbers separated by spaces. The idea of mpz_set_str may be to pass the whole number, and only that, to the argument.
Using the low line (underbar) '_' may be a good choice, better than space ' ' as it does not cause a confusion with a sequence of tokens. But also better than '.' and ',' (the WP also mentions thin space, or half-space " ", and apostrophe "'"), because traditionally numbers are monospace even in variable space fonts so that they line up in tables. So if '_' has the same width as the numbers, that tradition can be kept. Not all variable with fonts do that, though.
But check with the GMP developers what they think.
More information about the gmp-discuss
mailing list