[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master c79444c 1/2: Move bignump, fixnump from C to Lisp
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master c79444c 1/2: Move bignump, fixnump from C to Lisp |
Date: |
Tue, 21 Aug 2018 22:24:44 -0400 (EDT) |
branch: master
commit c79444c5b7b8ead1ea98ed5603bf2a49c13dbf16
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
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 8c92de1..a094003 100644
--- a/doc/lispref/objects.texi
+++ b/doc/lispref/objects.texi
@@ -190,9 +190,10 @@ but many machines provide a wider range.
fixnum will return a bignum instead.
Fixnums can be compared with @code{eq}, but bignums require
address@hidden or @code{=}. The @code{fixnump} predicate can be used to
-detect such small integers, and @code{bignump} can be used to detect
-large integers.
address@hidden or @code{=}. To test whether an integer is a fixnum or a
+bignum, you can compare it to @code{most-negative-fixnum} and
address@hidden, or you can use the convenience predicates
address@hidden 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 cafa483..9e880bc 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -366,6 +366,15 @@ was called."
(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 4c6d33f..08c7271 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);