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:
@@ -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)))
|
||||
|
||||
Reference in New Issue
Block a user