Subject: bug#43764: Calc shift right broken

From: Mattias Engdegård <[email-masked]>
Date: Thu, 8 Oct 2020 14:24:02 +0200

6 okt. 2020 kl. 03.28 skrev Lars Ingebrigtsen <[email-masked]>:

> On the other hand, I don't know what people use Calc for here. If
> people are going "I wonder what would happen on a 32-bit machine if I
> were to do this shift operation", then it'd be something else...

Yes, we should be defending the users of Emacs, not Emacs itself.

What about a narrower change: clip the value after shifting right instead of before?

Vincent, would you be happy with the patch below, or do you think a more fundamental change is required?

--- a/lisp/calc/calc-bin.el
+++ b/lisp/calc/calc-bin.el
@@ -375,7 +375,7 @@ calcFunc-lsh
                 (Math-lessp w n))
             0)
            ((< n 0)
-            (math-quotient (math-clip a w) (math-power-of-2 (- n))))
+             (math-clip (math-quotient a (math-power-of-2 (- n))) w))
            (t
             (math-clip (math-mul a (math-power-of-2 n)) w))))))