diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2020-10-09 11:12:53 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2020-10-09 11:24:15 +0200 |
commit | 35478f3f76d55f640372028889c570647432859c (patch) | |
tree | 3744cb3c1b0f9c159214a24f24ae4551386a852b /lisp/calc/calc-bin.el | |
parent | c69c17d573860ebe74320cee2a1850baa865183d (diff) | |
download | emacs-35478f3f76d55f640372028889c570647432859c.tar.gz |
Calc: fix arithmetic right shift sign bit detection
Arithmetic right shift didn't compute the bit to shift in correctly.
For example, #x600000000 right-shifted 8 steps (with 32 bit word size)
resulted in #xff000000 rather than 0. (Bug#43764)
* lisp/calc/calc-bin.el (calcFunc-ash): Fix condition.
* test/lisp/calc/calc-tests.el (calc-tests--clip, calc-tests--lsh)
(calc-tests--rsh, calc-tests--ash, calc-tests--rash, calc-tests--rot):
New.
(calc-shift-binary): New test.
Diffstat (limited to 'lisp/calc/calc-bin.el')
-rw-r--r-- | lisp/calc/calc-bin.el | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lisp/calc/calc-bin.el b/lisp/calc/calc-bin.el index 33fd1af6ffb..aa10d55e52c 100644 --- a/lisp/calc/calc-bin.el +++ b/lisp/calc/calc-bin.el @@ -403,7 +403,7 @@ (setq a (math-clip a w))) (let ((two-to-sizem1 (math-power-of-2 (1- w))) (sh (calcFunc-lsh a n w))) - (cond ((Math-natnum-lessp a two-to-sizem1) + (cond ((zerop (logand a two-to-sizem1)) sh) ((Math-lessp n (- 1 w)) (math-add (math-mul two-to-sizem1 2) -1)) |