emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master e1e60e51bf 2/2: Accept bignum arguments in `take` and `ntake`


From: Mattias Engdegård
Subject: master e1e60e51bf 2/2: Accept bignum arguments in `take` and `ntake`
Date: Tue, 30 Aug 2022 10:51:20 -0400 (EDT)

branch: master
commit e1e60e51bf324aaa2137075827c4d08a331a7bef
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Accept bignum arguments in `take` and `ntake`
    
    * src/fns.c (Ftake, Fntake): Accept any integer as first argument, for
    completeness.
    * test/src/fns-tests.el (fns--take-ntake): Add test cases.
---
 src/fns.c             | 20 ++++++++++++++++++--
 test/src/fns-tests.el | 10 +++++++++-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/fns.c b/src/fns.c
index 7e78bba3a0..07102256fe 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1563,7 +1563,15 @@ If N is zero or negative, return nil.
 If N is greater or equal to the length of LIST, return LIST (or a copy).  */)
   (Lisp_Object n, Lisp_Object list)
 {
-  CHECK_FIXNUM (n);
+  if (BIGNUMP (n))
+    {
+      if (mpz_sgn (*xbignum_val (n)) < 0)
+       return Qnil;
+      CHECK_LIST (list);
+      return list;
+    }
+  if (!FIXNUMP (n))
+    wrong_type_argument (Qintegerp, n);
   EMACS_INT m = XFIXNUM (n);
   if (m <= 0)
     return Qnil;
@@ -1594,7 +1602,15 @@ If N is greater or equal to the length of LIST, return 
LIST unmodified.
 Otherwise, return LIST after truncating it.  */)
   (Lisp_Object n, Lisp_Object list)
 {
-  CHECK_FIXNUM (n);
+  if (BIGNUMP (n))
+    {
+      if (mpz_sgn (*xbignum_val (n)) < 0)
+       return Qnil;
+      CHECK_LIST (list);
+      return list;
+    }
+  if (!FIXNUMP (n))
+    wrong_type_argument (Qintegerp, n);
   EMACS_INT m = XFIXNUM (n);
   if (m <= 0)
     return Qnil;
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index a84cce3ad4..4ef428af03 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -1412,6 +1412,14 @@
     (should (equal (take 5 list) '(a b c b c)))
     (should (equal (take 10 list) '(a b c b c b c b c b)))
 
-    (should (equal (ntake 10 list) '(a b)))))
+    (should (equal (ntake 10 list) '(a b))))
+
+  ;; Bignum N argument.
+  (let ((list (list 'a 'b 'c)))
+    (should (equal (take (+ most-positive-fixnum 1) list) '(a b c)))
+    (should (equal (take (- most-negative-fixnum 1) list) nil))
+    (should (equal (ntake (+ most-positive-fixnum 1) list) '(a b c)))
+    (should (equal (ntake (- most-negative-fixnum 1) list) nil))
+    (should (equal list '(a b c)))))
 
 ;;; fns-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]