emacs-devel
[Top][All Lists]
Advanced

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

Re: Using the GNU GMP Library for Bignums in Emacs


From: Helmut Eller
Subject: Re: Using the GNU GMP Library for Bignums in Emacs
Date: Tue, 24 Apr 2018 07:45:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

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




reply via email to

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