From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.devel Subject: Re: integer overflow handling for most-negative-fixnum Date: Sat, 21 Jul 2018 14:42:20 +0200 Message-ID: References: <867elsq78b.fsf@gmail.com> <866018yl76.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1532176840 5992 195.159.176.226 (21 Jul 2018 12:40:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 21 Jul 2018 12:40:40 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jul 21 14:40:36 2018 Return-path: Envelope-to: ged-emacs-devel@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 1fgrBc-0001Rf-Ek for ged-emacs-devel@m.gmane.org; Sat, 21 Jul 2018 14:40:36 +0200 Original-Received: from localhost ([::1]:52086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgrDh-0006qA-NP for ged-emacs-devel@m.gmane.org; Sat, 21 Jul 2018 08:42:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgrDY-0006pk-Hc for emacs-devel@gnu.org; Sat, 21 Jul 2018 08:42:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgrDX-00054Q-EM for emacs-devel@gnu.org; Sat, 21 Jul 2018 08:42:36 -0400 Original-Received: from [195.159.176.226] (port=59885 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fgrDX-00054B-6E for emacs-devel@gnu.org; Sat, 21 Jul 2018 08:42:35 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fgrBM-0001Dv-To for emacs-devel@gnu.org; Sat, 21 Jul 2018 14:40:20 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 23 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:KjP9fUCI9HJXulQaQZ3wVh2Y4mg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:227612 Archived-At: > Either the print routines or the reader have a bug. Read and print work just fine: (= (read (prin1-to-string most-negative-fixnum)) most-negative-fixnum) => t The problem is (format "%x" most-negative-fixnum) => "2000000000000000". If this should return "-1" that would obviously be an incompatible change. And in many cases one really wants to "see" the two complement representation of negative fixnums. Just like in gdb: p/x -1 prints 0xffffff. Interestingly, gdb doesn't seem to have a mode to print hex numbers with a negative sign; so I guess nobody ever wanted that. In contrast, it should be unproblematic to add an optional base argument to number-to-string. So (number-to-string -1 16) could return "-2000000000000000" without breaking anything. Actually, I occasionally wondered why string-to-number accepts a base argument but number-to-string doesn't. (Of course, the question what (format "%x" ) should do is still open; the easiest would probably be to signal an error.) Helmut