[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: integer overflow handling for most-negative-fixnum
From: |
Helmut Eller |
Subject: |
Re: integer overflow handling for most-negative-fixnum |
Date: |
Sat, 21 Jul 2018 14:42:20 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
> 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" <bignum>) should do is still
open; the easiest would probably be to signal an error.)
Helmut
- Re: integer overflow handling for most-negative-fixnum, (continued)
- Re: integer overflow handling for most-negative-fixnum, Eli Zaretskii, 2018/07/21
- Re: integer overflow handling for most-negative-fixnum, Paul Eggert, 2018/07/21
- Re: integer overflow handling for most-negative-fixnum, Eli Zaretskii, 2018/07/21
- Re: integer overflow handling for most-negative-fixnum, Stefan Monnier, 2018/07/21
- Re: integer overflow handling for most-negative-fixnum, Eli Zaretskii, 2018/07/21
- Re: integer overflow handling for most-negative-fixnum, Stefan Monnier, 2018/07/21
- Re: integer overflow handling for most-negative-fixnum,
Helmut Eller <=
- Re: integer overflow handling for most-negative-fixnum, Paul Eggert, 2018/07/21
- Re: integer overflow handling for most-negative-fixnum, Andy Moreton, 2018/07/23
- Re: integer overflow handling for most-negative-fixnum, Paul Eggert, 2018/07/23
- Re: integer overflow handling for most-negative-fixnum, Andy Moreton, 2018/07/23
- Re: integer overflow handling for most-negative-fixnum, Andreas Schwab, 2018/07/24
- Re: integer overflow handling for most-negative-fixnum, Andy Moreton, 2018/07/24
Re: integer overflow handling for most-negative-fixnum, Paul Eggert, 2018/07/21