|
From: | Jefferson Carpenter |
Subject: | Re: Using the GNU GMP Library for Bignums in Emacs |
Date: | Sun, 3 Jun 2018 23:44:55 +0000 |
User-agent: | Mozilla/5.0 (Windows NT 6.2; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 |
On 4/24/2018 5:45 AM, Helmut Eller wrote:
On Mon, Apr 23 2018, Paul Eggert wrote:Even in the standard C library (which lacks bignums), the %x printf format is supposed to be used only with unsigned integers. Nowadays GCC even optionally warns about using %x on signed integers.Maybe %x should then print the (shortest) two's complement representation for bignums. In Common Lisp: (defun 2comp (x) (format nil "~x" (logand x (1- (ash 1 (+ 1 (integer-length x))))))) (2comp -1) => "1" (2comp -2) => "2" (2comp -3) => "5" (2comp -15) => "11" (2comp -16) => "10" In practice, only integers smaller than most-negative-fixnum would use this rule. Helmut
I don't think that would make sense, because you can't tell whether a given output string was generated from a positive or a negative number.
For instance, (2comp -6) = (2comp 10) = "A"."Two's complement" isn't a representation of integers; "N-bit two's complement" is a representation of integers from -2^N to 2^N-1, for positive integer N.
So, I think that function should take another argument, the number of bits `n` to output.
Jefferson
[Prev in Thread] | Current Thread | [Next in Thread] |