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 to use ash instead, unless COUNT could ever be negative, and if, when COUNT is negative, your program really needs the special treatment of negative COUNT provided by this function.

View in manual

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
to use `ash' instead, unless COUNT could ever be negative, and
if, when COUNT is negative, your program really needs the special
treatment of negative COUNT provided by this function."
  (declare (compiler-macro
            (lambda (form)
              (macroexp-warn-and-return "avoid `lsh'; use `ash' instead"
                                        form '(suspicious lsh) t form))))
  (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))