aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Kaludercic <philipk@posteo.net>2025-02-20 23:56:46 +0100
committerPhilip Kaludercic <philipk@posteo.net>2025-02-21 00:11:28 +0100
commit54f65f2005f256de1771d9ab9899ae3d519504a4 (patch)
tree18e6eccaa26565e29706f50aceb6b19050ceeca4
parent03e173ff2fc625e29249ece8a774695cbb3196d3 (diff)
compat-31: Add evenp and oddp
See https://github.com/emacs-compat/compat/issues/63.
-rw-r--r--compat-31.el9
-rw-r--r--compat-tests.el32
-rw-r--r--compat.texi12
3 files changed, 52 insertions, 1 deletions
diff --git a/compat-31.el b/compat-31.el
index cd519c6..cdd79a7 100644
--- a/compat-31.el
+++ b/compat-31.el
@@ -27,6 +27,15 @@
;; TODO Update to 31.1 as soon as the Emacs emacs-31 branch version bumped
(compat-version "31.0.50")
+;;;; Defined in subr.el
+
+(compat-defun oddp (integer)
+ "Return t if INTEGER is odd."
+ (not (eq (% integer 2) 0)))
+
+(compat-defun evenp (integer)
+ "Return t if INTEGER is even."
+ (eq (% integer 2) 0))
(provide 'compat-31)
;;; compat-31.el ends here
diff --git a/compat-tests.el b/compat-tests.el
index 223d0dd..3b52d0d 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -3254,5 +3254,37 @@
(trusted-content '("compat-tests.el")))
(should-not (trusted-content-p))))
+(ert-deftest compat-oddp ()
+ (should (oddp 1))
+ (should (oddp -1))
+ (should (oddp 3))
+ (should (oddp most-positive-fixnum))
+ (when (fboundp 'bignump)
+ (should (oddp (+ most-positive-fixnum 2))))
+ (should-not (oddp 0))
+ (should-not (oddp -2))
+ (should-not (oddp 10))
+ (should-not (oddp (1- most-positive-fixnum)))
+ (when (fboundp 'bignump)
+ (should-not (oddp (1+ most-positive-fixnum))))
+ (should-error (oddp 1.0))
+ (should-error (oddp 0.0)))
+
+(ert-deftest compat-evenp ()
+ (should (evenp 0))
+ (should (evenp -2))
+ (should (evenp 10))
+ (should (evenp (1- most-positive-fixnum)))
+ (when (fboundp 'bignump)
+ (should (evenp (1+ most-positive-fixnum))))
+ (should-not (evenp 1))
+ (should-not (evenp -1))
+ (should-not (evenp 3))
+ (should-not (evenp most-positive-fixnum))
+ (when (fboundp 'bignump)
+ (should-not (evenp (+ most-positive-fixnum 2))))
+ (should-error (evenp 1.0))
+ (should-error (evenp 0.0)))
+
(provide 'compat-tests)
;;; compat-tests.el ends here
diff --git a/compat.texi b/compat.texi
index 2743071..51472ce 100644
--- a/compat.texi
+++ b/compat.texi
@@ -3698,7 +3698,17 @@ older than 31.1. Note that due to upstream changes, it might happen
that there will be the need for changes, so use these functions with
care.
-@c Placeholder
+@c copied from lispref/numbers.texi
+@defun oddp integer
+This predicate tests whether its argument is an odd number, and returns
+@code{t} if so, @code{nil} otherwise. The argument must be an integer.
+@end defun
+
+@c copied from lispref/numbers.texi
+@defun evenp integer
+This predicate tests whether its argument is an even number, and returns
+@code{t} if so, @code{nil} otherwise. The argument must be an integer.
+@end defun
@subsection Extended Definitions
These functions must be called explicitly via @code{compat-call},