1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-09 13:10:57 -08:00

Don’t signal overflow for (expt 1 bignum)

Similarly for (expt 0 bignum) and (expt -1 bignum).
The result is always a -1, 0 or 1, so do not signal overflow.
* src/data.c (expt_integer): Do not signal an overflow if
-1 <= X <= 1.  Be clearer about when overflow is signaled.
* test/src/floatfns-tests.el (bignum-expt): Test this.
This commit is contained in:
Paul Eggert 2019-11-04 23:10:12 -08:00
parent 96c8e4fa41
commit 5ab29400a4
2 changed files with 26 additions and 6 deletions

View file

@ -51,7 +51,12 @@
(ert-deftest bignum-expt ()
(dolist (n (list most-positive-fixnum (1+ most-positive-fixnum)
most-negative-fixnum (1- most-negative-fixnum)
(* 5 most-negative-fixnum)
(* 5 (1+ most-positive-fixnum))
-2 -1 0 1 2))
(should (or (<= n 0) (= (expt 0 n) 0)))
(should (= (expt 1 n) 1))
(should (or (< n 0) (= (expt -1 n) (if (zerop (logand n 1)) 1 -1))))
(should (= (expt n 0) 1))
(should (= (expt n 1) n))
(should (= (expt n 2) (* n n)))