Function: lsh
lsh is a byte-compiled function defined in subr.el.gz.
Signature
(lsh VALUE COUNT)
Documentation
Return VALUE with its bits shifted left by COUNT.
If COUNT is negative, shifting is actually to the right.
In this case, if VALUE is a negative fixnum treat it as unsigned,
i.e., subtract 2 * most-negative-fixnum from VALUE before shifting it.
Most uses of this function turn out to be mistakes. We recommend using
ash instead, unless COUNT could ever be negative, in which case your
program should only use this function if it specifically requires the
special handling of negative COUNT.
Probably introduced at or before Emacs version 29.1.
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defun lsh (value count)
"Return VALUE with its bits shifted left by COUNT.
If COUNT is negative, shifting is actually to the right.
In this case, if VALUE is a negative fixnum treat it as unsigned,
i.e., subtract 2 * `most-negative-fixnum' from VALUE before shifting it.
Most uses of this function turn out to be mistakes. We recommend using
`ash' instead, unless COUNT could ever be negative, in which case your
program should only use this function if it specifically requires the
special handling of negative COUNT."
(declare (ftype (function (integer integer) integer))
(compiler-macro
(lambda (form)
(macroexp-warn-and-return
(format-message "avoid `lsh'; use `ash' instead")
form '(suspicious lsh) t form)))
(side-effect-free t))
(when (and (< value 0) (< count 0))
(when (< value most-negative-fixnum)
(signal 'args-out-of-range (list value count)))
(setq value (logand (ash value -1) most-positive-fixnum))
(setq count (1+ count)))
(ash value count))