[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using the GNU GMP Library for Bignums in Emacs

From: Paul Eggert
Subject: Re: Using the GNU GMP Library for Bignums in Emacs
Date: Sun, 22 Apr 2018 21:41:02 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

Richard Stallman wrote:
   > The usual approach for this is to format negative numbers with a leading 
   > sign, so that (format "%x" -1) returns "-1". This is what Emac Lisp should 

I think that change is likely to break things.  If you WANT a hex
string, you probably want it to be all hex, regardless of value.

No doubt people occasionally want C-like formatting (i.e., print a negative number modulo 2**W where W is the word width), but once we have bignums the notion of the "word width" becomes dubious, and in practice it's cleaner and more useful to print hexadecimal integers in the usual mathematical way. That's the tradition in Common Lisp, in Python, and in every other language I know that has bignums and has the %x format or something similar.

I would expect that each use of %x probably has a certain number of bits
in mind.  Perhaps %x should take a number of bits and output modularly.
So %24x would output 24 bits' worth.

We could invent a special syntax along those lines, though it would need to differ from "%24x" which already means pad with spaces to 24 characters. However, there's little point to a special syntax since one can easily achieve the same effect without it. For example, to format the low-order 24 bits of N, one can already use (format "%x" (logand N #xffffff)) and this will continue to work even if bignums are introduced.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]