Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers

From: Helmut Eller <[email-masked]>
Date: Tue, 24 Jul 2018 20:15:57 +0200

On Tue, Jul 24 2018, Paul Eggert wrote:

>> With your change %x will also have quite a different meaning in C11.
>
> Not really, as Emacs (format "%x" N) agrees with C11 printf ("%x", N)
> in all values of N that are valid in both languages. In C11, negative
> values are not valid, as printf ("%x", N) has undefined behavior when
> N is negative. So we are discussing an area where Emacs Lisp can
> define behavior without introducing incompatibilities with C11.

In practice, printf ("%x", (int)N) prints the bits in N as unsigned
integer not as signed integer.

> If we changed (format "%x" -1) to signal an error instead, that would
> also be upward-compatible with C11. However, it's more useful for
> something like (format "#x%x" -1) to output a string that can 'read'
> can scan to get -1, something that's not true of Emacs now.

#x-1 maybe interesting to the read function but it's not interesting to
humans.  Humans want to see #x3fffffffffffffff.

>>> This seems like overkill for such a small
>>> change to functionality that hardly ever matters; plus, %x, %X and %o
>>> would continue to have problematic machine-dependent semantics and
>>> would not be sensibly extensible to bignums.
>>
>> If it doesn't matter to you then why make the change/break at all?
>
> It does matter to me, actually.

If it matters to you then you should have no problem with introducing an
new specifier for this.

> I think Emacs should have sensible behavior even in corner cases that
> hardly ever arise in real programs.

That %x prints the two's complement representation for negative fixnums
is fairly sensible behavior.  Emacs should not change such basic things
or for that matter start to print ’ instead of '.  Such changes would be
the opposite of sensible.

Helmut