From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Moreton Newsgroups: gmane.emacs.bugs Subject: bug#32252: [PATCH] %o and %x now format signed numbers Date: Tue, 24 Jul 2018 17:26:57 +0100 Message-ID: References: <7e8dd084-7ab9-c2ce-1d6c-e673fa998f11@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1532449567 7427 195.159.176.226 (24 Jul 2018 16:26:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 24 Jul 2018 16:26:07 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (windows-nt) To: 32252@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 24 18:26:03 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fi08Q-0001n4-Mo for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Jul 2018 18:26:02 +0200 Original-Received: from localhost ([::1]:41467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fi0AV-0005GV-QG for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Jul 2018 12:28:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fi0AP-0005GE-TT for bug-gnu-emacs@gnu.org; Tue, 24 Jul 2018 12:28:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fi0AM-00081H-Fj for bug-gnu-emacs@gnu.org; Tue, 24 Jul 2018 12:28:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50684) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fi0AM-00080y-B4 for bug-gnu-emacs@gnu.org; Tue, 24 Jul 2018 12:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fi0AM-000298-2k for bug-gnu-emacs@gnu.org; Tue, 24 Jul 2018 12:28:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <20180723191250.19182-1-eggert@cs.ucla.edu> Resent-From: Andy Moreton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Jul 2018 16:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32252 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15324496408192 (code B ref -1); Tue, 24 Jul 2018 16:28:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 24 Jul 2018 16:27:20 +0000 Original-Received: from localhost ([127.0.0.1]:55702 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fi09g-000284-JC for submit@debbugs.gnu.org; Tue, 24 Jul 2018 12:27:20 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58763) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fi09e-00027q-FK for submit@debbugs.gnu.org; Tue, 24 Jul 2018 12:27:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fi09Y-0007SU-4h for submit@debbugs.gnu.org; Tue, 24 Jul 2018 12:27:13 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:41179) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fi09Y-0007SJ-06 for submit@debbugs.gnu.org; Tue, 24 Jul 2018 12:27:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fi09W-0005Dn-Nj for bug-gnu-emacs@gnu.org; Tue, 24 Jul 2018 12:27:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fi09T-0007OM-Hf for bug-gnu-emacs@gnu.org; Tue, 24 Jul 2018 12:27:10 -0400 Original-Received: from [195.159.176.226] (port=44908 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fi09T-0007Ml-9y for bug-gnu-emacs@gnu.org; Tue, 24 Jul 2018 12:27:07 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fi07J-0000N3-S4 for bug-gnu-emacs@gnu.org; Tue, 24 Jul 2018 18:24:53 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 44 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:s04MmLd0QlPme+e8ZyNjzZMuF78= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:148893 Archived-At: 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