>From c79444c5b7b8ead1ea98ed5603bf2a49c13dbf16 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 21 Aug 2018 16:06:58 -0700 Subject: [PATCH 1/2] Move bignump, fixnump from C to Lisp * doc/lispref/objects.texi (Integer Type): Mention most-negative-fixnum and most-positive-fixnum as alternatives to fixnump and bignump. * lisp/subr.el (fixnump, bignump): Now written in Lisp. * src/data.c (Ffixnump, Fbignump): No longer written in C, as these new functions are not crucial for performance. --- doc/lispref/objects.texi | 7 ++++--- lisp/subr.el | 9 +++++++++ src/data.c | 21 --------------------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index 8c92de123c..a0940032ee 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi @@ -190,9 +190,10 @@ Integer Type fixnum will return a bignum instead. Fixnums can be compared with @code{eq}, but bignums require -@code{eql} or @code{=}. The @code{fixnump} predicate can be used to -detect such small integers, and @code{bignump} can be used to detect -large integers. +@code{eql} or @code{=}. To test whether an integer is a fixnum or a +bignum, you can compare it to @code{most-negative-fixnum} and +@code{most-positive-fixnum}, or you can use the convenience predicates +@code{fixnump} and @code{bignump} on any object. The read syntax for integers is a sequence of (base ten) digits with an optional sign at the beginning and an optional period at the end. The diff --git a/lisp/subr.el b/lisp/subr.el index cafa4835ea..9e880bc880 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -366,6 +366,15 @@ zerop (declare (compiler-macro (lambda (_) `(= 0 ,number)))) (= 0 number)) +(defun fixnump (object) + "Return t if OBJECT is a fixnum." + (and (integerp object) + (<= most-negative-fixnum object most-positive-fixnum))) + +(defun bignump (object) + "Return t if OBJECT is a bignum." + (and (integerp object) (not (fixnump object)))) + (defun lsh (value count) "Return VALUE with its bits shifted left by COUNT. If COUNT is negative, shifting is actually to the right. diff --git a/src/data.c b/src/data.c index 4c6d33f294..08c7271dd7 100644 --- a/src/data.c +++ b/src/data.c @@ -511,16 +511,6 @@ DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, return Qnil; } -DEFUN ("fixnump", Ffixnump, Sfixnump, 1, 1, 0, - doc: /* Return t if OBJECT is an fixnum. */ - attributes: const) - (Lisp_Object object) -{ - if (FIXNUMP (object)) - return Qt; - return Qnil; -} - DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0, doc: /* Return t if OBJECT is an integer or a marker (editor pointer). */) (register Lisp_Object object) @@ -598,15 +588,6 @@ DEFUN ("condition-variable-p", Fcondition_variable_p, Scondition_variable_p, return Qt; return Qnil; } - -DEFUN ("bignump", Fbignump, Sbignump, 1, 1, 0, - doc: /* Return t if OBJECT is a bignum. */) - (Lisp_Object object) -{ - if (BIGNUMP (object)) - return Qt; - return Qnil; -} /* Extract and set components of lists. */ @@ -4153,7 +4134,6 @@ syms_of_data (void) defsubr (&Sconsp); defsubr (&Satom); defsubr (&Sintegerp); - defsubr (&Sfixnump); defsubr (&Sinteger_or_marker_p); defsubr (&Snumberp); defsubr (&Snumber_or_marker_p); @@ -4179,7 +4159,6 @@ syms_of_data (void) defsubr (&Sthreadp); defsubr (&Smutexp); defsubr (&Scondition_variable_p); - defsubr (&Sbignump); defsubr (&Scar); defsubr (&Scdr); defsubr (&Scar_safe); -- 2.17.1