bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Helmut Eller
Subject: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 08:58:25 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

On Tue, Jul 24 2018, Paul Eggert wrote:

> Helmut Eller wrote:
>
>> In practice, printf ("%x", (int)N) prints the bits in N as unsigned
>> integer not as signed integer.
>
> That's two operations not one, and even there the results disagree
> with what (format "%x" N) does. On every Emacs platform I've ever used
> the C output begins with a different hex digit than the Emacs Lisp
> output. Emacs has never done %x just like that unportable C code, and
> likely will never do so.

Nobody is arguing for printing the tag-bits.  And what Emacs has done is
fairly obvious to everybody.

>> #x-1 maybe interesting to the read function but it's not interesting to
>> humans.  Humans want to see #x3fffffffffffffff.
>
> I doubt very much that most humans really want to see an error-prone
> notation like that (can you easily spot the difference between it and
> #x3ffffffffffffffff? I can't). And even if some humans did want it,
> they won't get it on 32-bit Emacs. This whole idea is a bad approach
> for Emacs.

What's more interesting:
(format "%x" (lognot 8)) => "-9"
or
(format "%x" (lognot 8)) => "3ffffffffffffff7"

For me, the first version is totally useless.

> What I expect most users would prefer is an approach where 'read' and
> 'format' are inverses, e.g., (read (printf "#x%x" N)) returns N for
> every integer N. Emacs doesn't do that now, and the proposed patch
> fixes things so that it does.

The inverse of read is print, not format or printf. 

> No other approach has been proposed that
> would make much sense (that is, be portable, be easily extendible to
> bignums, that sort of thing).

Of course there have been proposals: Do your bignum stuff with a
different format specifier.

Here is another proposal: Add a read syntax for unsigned fixnums like
#x3fffffffffffffffu or alternatively #xu3fffffffffffffff.

>> you should have no problem with introducing an
>> new specifier for this.
>
> I'd rather not, as the hex stuff has never worked right in Emacs and
> we shouldn't be codifying old bugs.

It was already codified in the documentation, even the much more dubios
flonum case.  It's really annoying when documented behavior changes.

Helmut





reply via email to

[Prev in Thread] Current Thread [Next in Thread]