GNU bug report logs - #32252
[PATCH] %o and %x now format signed numbers

Previous Next

Package: emacs;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Mon, 23 Jul 2018 19:14:02 UTC

Severity: normal

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


Message #53 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
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




This bug report was last modified 2 years and 322 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.