From Newsgroup: comp.lang.lisp
On 2025-10-24, Alan Bawden <
alan@csail.mit.edu> wrote:
Madhu <enometh@meer.net> writes:
something like this then, does it miss out any case?
(defun fixed-width-ash (width value count)
(if (< count 0)
(ash (logand value (lognot (ash -1 width))) count)
(ash (logandc2 value (ash -1 width)) count)))
Uh, guys, my point was that (logandc2 x y) and (logand x (lognot y))
compute _exactly_ the same thing...
So I'm looking for the logtrunc function and it's not there!
Right, it's something I added in TXR Lisp, which is not in Common Lisp.
(defun lsh (width value count) ;; ash -> arithmetic shift; lsh -> logical
(ash (logtrunc value width) count))
logtrunc truncates an integer to the specified number of binary
digits, producing a nonnegative value. Negative integers are taken to be in the familiar "infinite two's complement", where we have a mantissa followed by an infinite number of sign bits that are 1, so that (logtrunc -1 8) produces 255, etc.
--- Synchronet 3.21d-Linux NewsLink 1.2