From: Andy Moreton <andrewjmoreton@gmail.com>
To: 32252@debbugs.gnu.org
Subject: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 17:26:57 +0100 [thread overview]
Message-ID: <vz136w8k3am.fsf@gmail.com> (raw)
In-Reply-To: <20180723191250.19182-1-eggert@cs.ucla.edu>
On Tue 24 Jul 2018, Paul Eggert wrote:
> Helmut Eller 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.
As emacs fixnums are signed, and the C printf conversion specifier "%x"
takes an unsigned int argument, there are expected to be differences in
behaviour.
However what matters in C (and in elisp) is not what the spec says, but
what the codebase of existing users does, and what existing library
implementations do.
When printing values with base!=10, it is always the underlying
representation (i.e. bit pattern) that is of interest, not the value
interpreted as a signed number. Long standing practice in many languages
shows values printed in hex, octal and binary as unsigned.
> 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.
I agree that there is a problem, but not with your solution.
I think it would be better to change the reader to treat non-base10
values as if they were unsigned representations, so that `format' is
unchanged, and (read (format "#x%x" -1)) evaluates to -1.
That is consistent wth other languages and user expectation.
> It does matter to me, actually. I think Emacs should have sensible behavior
> even in corner cases that hardly ever arise in real programs.
I agree: a consistent model of behaviour is important, even if it may
take a while to fix buggy behaviour that disagrees with the model.
AndyM
next prev parent reply other threads:[~2018-07-24 16:26 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-23 19:12 bug#32252: [PATCH] %o and %x now format signed numbers Paul Eggert
2018-07-23 19:48 ` Helmut Eller
2018-07-23 19:49 ` Drew Adams
2018-07-23 23:30 ` Paul Eggert
2018-07-24 1:20 ` Drew Adams
2018-07-24 2:04 ` Paul Eggert
2018-07-24 2:38 ` Eli Zaretskii
2018-07-24 2:44 ` Paul Eggert
2018-07-24 14:29 ` Eli Zaretskii
2018-07-24 4:15 ` Drew Adams
2018-07-23 23:39 ` Paul Eggert
2018-07-24 1:16 ` Drew Adams
2018-07-25 3:53 ` Richard Stallman
2018-07-25 21:56 ` Drew Adams
2018-07-27 3:20 ` Richard Stallman
2018-07-24 4:49 ` Helmut Eller
2018-07-24 14:22 ` Paul Eggert
2018-07-24 14:35 ` Andreas Schwab
2018-07-24 18:15 ` Helmut Eller
2018-07-25 0:50 ` Paul Eggert
2018-07-25 2:41 ` Eli Zaretskii
2018-07-25 17:21 ` Paul Eggert
2018-07-25 17:28 ` Eli Zaretskii
2018-07-26 7:44 ` Paul Eggert
2018-07-26 8:04 ` Helmut Eller
2018-07-26 8:16 ` Paul Eggert
2018-07-25 6:58 ` Helmut Eller
2018-07-26 7:59 ` Paul Eggert
2018-07-26 8:43 ` Helmut Eller
2018-07-26 9:15 ` Paul Eggert
2018-07-26 9:39 ` Helmut Eller
2018-07-26 9:31 ` Andreas Schwab
2018-07-26 9:40 ` Robert Pluim
2018-07-26 9:56 ` Helmut Eller
2018-07-26 16:55 ` Paul Eggert
2018-07-26 17:16 ` Helmut Eller
2018-07-26 17:50 ` Paul Eggert
2018-07-26 18:35 ` Helmut Eller
2018-07-26 21:07 ` Paul Eggert
2018-07-24 18:27 ` Eli Zaretskii
2018-07-25 0:54 ` Paul Eggert
2018-07-25 8:09 ` Andreas Schwab
2018-07-25 20:16 ` Paul Eggert
2018-07-25 14:17 ` Eli Zaretskii
2018-07-25 23:33 ` Brett Gilio
2018-07-26 7:26 ` Paul Eggert
2018-07-24 16:26 ` Andy Moreton [this message]
2018-07-25 10:08 ` Andy Moreton
2018-07-26 12:52 ` Andy Moreton
2018-07-26 12:54 ` Andy Moreton
2018-07-26 17:18 ` Helmut Eller
2018-08-23 9:37 ` Helmut Eller
2022-07-04 1:03 ` bug#32252: i find binary-as-unsigned to be very helpful snickerbockers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=vz136w8k3am.fsf@gmail.com \
--to=andrewjmoreton@gmail.com \
--cc=32252@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).