|
From: | Paul Eggert |
Subject: | Re: integer overflow handling for most-negative-fixnum |
Date: | Mon, 23 Jul 2018 16:09:54 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 |
On 07/23/2018 12:57 PM, Stefan Monnier wrote:
Another option for the "bitwidth case" is to do it outside of `format`. I.e. instead of (format "%/32x" n) you'd use (format "%x" (truncate-to-bitwidth n 32)) where `truncate-to-bitwidth` would turn a negative number into its positive equivalent (mod 2^bitwidth). That shouldn't be too hard to implement in Elisp once we have bignums.
Yes, with bignums it can be implemented this way, if I understand you aright:
(defun truncate-to-bitwidth (num bits) (logand num (- (lsh 1 bits) 1)))
[Prev in Thread] | Current Thread | [Next in Thread] |