aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPaul Eggert2018-08-18 15:20:46 -0700
committerPaul Eggert2018-08-18 15:22:35 -0700
commit673b1785db4604efe81b8045a9d8ab68936af719 (patch)
tree0f78d72a7d4eef42b62bcfbaec2627aa04986c80 /test
parent877cd22f553624b6d7f24141acd134f9cf839259 (diff)
downloademacs-673b1785db4604efe81b8045a9d8ab68936af719.tar.gz
emacs-673b1785db4604efe81b8045a9d8ab68936af719.zip
Restore traditional lsh behavior on fixnums
* doc/lispref/numbers.texi (Bitwise Operations): Document that the traditional (lsh A B) behavior is for fixnums, and that it is an error if A and B are both negative and A is a bignum. See Bug#32463. * lisp/subr.el (lsh): New function, moved here from src/data.c. * src/data.c (ash_lsh_impl): Remove, moving body into Fash since it’s the only caller now. (Fash): Check for out-of-range counts. If COUNT is zero, return first argument instead of going through libgmp. Omit lsh code since lsh is now done in Lisp. Add code for shifting fixnums right, to avoid a round trip through libgmp. (Flsh): Remove; moved to lisp/subr.el. * test/lisp/international/ccl-tests.el (shift): Test for traditional lsh behavior, instead of assuming lsh is like ash when bignums are present. * test/src/data-tests.el (data-tests-logand) (data-tests-logior, data-tests-logxor, data-tests-ash-lsh): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/international/ccl-tests.el21
-rw-r--r--test/src/data-tests.el16
2 files changed, 18 insertions, 19 deletions
diff --git a/test/lisp/international/ccl-tests.el b/test/lisp/international/ccl-tests.el
index b41b8c1ff64..7dd7224726b 100644
--- a/test/lisp/international/ccl-tests.el
+++ b/test/lisp/international/ccl-tests.el
@@ -37,18 +37,9 @@
37 37
38 ;; shift right -ve -5628 #x3fffffffffffea04 38 ;; shift right -ve -5628 #x3fffffffffffea04
39 (should (= (ash -5628 -8) -22)) ; #x3fffffffffffffea 39 (should (= (ash -5628 -8) -22)) ; #x3fffffffffffffea
40 40 (should (= (lsh -5628 -8)
41 ;; shift right -5628 #x3fffffffffffea04 41 (ash (- -5628 (ash most-negative-fixnum 1)) -8)
42 (cond 42 (ash (logand (ash -5628 -1) most-positive-fixnum) -7))))
43 ((fboundp 'bignump)
44 (should (= (lsh -5628 -8) -22))) ; #x3fffffffffffffea bignum
45 ((= (logb most-negative-fixnum) 61)
46 (should (= (lsh -5628 -8)
47 (string-to-number
48 "18014398509481962")))) ; #x003fffffffffffea master (64bit)
49 ((= (logb most-negative-fixnum) 29)
50 (should (= (lsh -5628 -8) 4194282))) ; #x003fffea master (32bit)
51 ))
52 43
53;; CCl program from `pgg-parse-crc24' in lisp/obsolete/pgg-parse.el 44;; CCl program from `pgg-parse-crc24' in lisp/obsolete/pgg-parse.el
54(defconst prog-pgg-source 45(defconst prog-pgg-source
@@ -177,11 +168,11 @@ At EOF:
177 82169 240 2555 18 128 81943 15 276 529 305 81 -17660 -17916 22]) 168 82169 240 2555 18 128 81943 15 276 529 305 81 -17660 -17916 22])
178 169
179(defconst prog-midi-dump 170(defconst prog-midi-dump
180"Out-buffer must be 2 times bigger than in-buffer. 171(concat "Out-buffer must be 2 times bigger than in-buffer.
181Main-body: 172Main-body:
182 2:[read-jump-cond-expr-const] read r0, if !(r0 < 128), jump to 22(+20) 173 2:[read-jump-cond-expr-const] read r0, if !(r0 < 128), jump to 22(+20)
183 5:[branch] jump to array[r3] of length 4 174 5:[branch] jump to array[r3] of length 4
184 11 12 15 18 22 175 11 12 15 18 22 ""
185 11:[jump] jump to 2(-9) 176 11:[jump] jump to 2(-9)
186 12:[set-register] r1 = r0 177 12:[set-register] r1 = r0
187 13:[set-register] r0 = r4 178 13:[set-register] r0 = r4
@@ -227,7 +218,7 @@ Main-body:
227 71:[jump] jump to 2(-69) 218 71:[jump] jump to 2(-69)
228At EOF: 219At EOF:
229 72:[end] end 220 72:[end] end
230") 221"))
231 222
232(ert-deftest ccl-compile-midi () 223(ert-deftest ccl-compile-midi ()
233 (should (equal (ccl-compile prog-midi-source) prog-midi-code))) 224 (should (equal (ccl-compile prog-midi-source) prog-midi-code)))
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index a4c6b0e4915..85cbab26106 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -598,7 +598,9 @@ comparing the subr with a much slower lisp implementation."
598 (should (fixnump (1- (1+ most-positive-fixnum))))) 598 (should (fixnump (1- (1+ most-positive-fixnum)))))
599 599
600(ert-deftest data-tests-logand () 600(ert-deftest data-tests-logand ()
601 (should (= -1 (logand -1))) 601 (should (= -1 (logand) (logand -1) (logand -1 -1)))
602 (let ((n (1+ most-positive-fixnum)))
603 (should (= (logand -1 n) n)))
602 (let ((n (* 2 most-negative-fixnum))) 604 (let ((n (* 2 most-negative-fixnum)))
603 (should (= (logand -1 n) n)))) 605 (should (= (logand -1 n) n))))
604 606
@@ -606,11 +608,11 @@ comparing the subr with a much slower lisp implementation."
606 (should (= (logcount (read "#xffffffffffffffffffffffffffffffff")) 128))) 608 (should (= (logcount (read "#xffffffffffffffffffffffffffffffff")) 128)))
607 609
608(ert-deftest data-tests-logior () 610(ert-deftest data-tests-logior ()
609 (should (= -1 (logior -1))) 611 (should (= -1 (logior -1) (logior -1 -1)))
610 (should (= -1 (logior most-positive-fixnum most-negative-fixnum)))) 612 (should (= -1 (logior most-positive-fixnum most-negative-fixnum))))
611 613
612(ert-deftest data-tests-logxor () 614(ert-deftest data-tests-logxor ()
613 (should (= -1 (logxor -1))) 615 (should (= -1 (logxor -1) (logxor -1 -1 -1)))
614 (let ((n (1+ most-positive-fixnum))) 616 (let ((n (1+ most-positive-fixnum)))
615 (should (= (logxor -1 n) (lognot n))))) 617 (should (= (logxor -1 n) (lognot n)))))
616 618
@@ -642,6 +644,12 @@ comparing the subr with a much slower lisp implementation."
642 (should (= (ash most-negative-fixnum 1) 644 (should (= (ash most-negative-fixnum 1)
643 (* most-negative-fixnum 2))) 645 (* most-negative-fixnum 2)))
644 (should (= (lsh most-negative-fixnum 1) 646 (should (= (lsh most-negative-fixnum 1)
645 (* most-negative-fixnum 2)))) 647 (* most-negative-fixnum 2)))
648 (should (= (ash (* 2 most-negative-fixnum) -1)
649 most-negative-fixnum))
650 (should (= (lsh most-positive-fixnum -1) (/ most-positive-fixnum 2)))
651 (should (= (lsh most-negative-fixnum -1) (lsh (- most-negative-fixnum) -1)))
652 (should (= (lsh -1 -1) most-positive-fixnum))
653 (should-error (lsh (1- most-negative-fixnum) -1)))
646 654
647;;; data-tests.el ends here 655;;; data-tests.el ends here