[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 575179f 2/5: Make (mod 1.0 0) consistent with (/ 1.
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master 575179f 2/5: Make (mod 1.0 0) consistent with (/ 1.0 0) |
Date: |
Sat, 24 Aug 2019 18:55:17 -0400 (EDT) |
branch: master
commit 575179f74d9b80ee468ae39239c853546da8de43
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
Make (mod 1.0 0) consistent with (/ 1.0 0)
* src/data.c (Fmod): Do not signal an error for (mod 1.0 0), for
the same reason (/ 1.0 0) does not signal an error.
* test/src/data-tests.el (data-tests-mod-0): New test.
---
src/data.c | 4 +++-
test/src/data-tests.el | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/data.c b/src/data.c
index 3896835..dfc8a89 100644
--- a/src/data.c
+++ b/src/data.c
@@ -3117,12 +3117,14 @@ Both X and Y must be numbers or markers. */)
{
CHECK_NUMBER_COERCE_MARKER (x);
CHECK_NUMBER_COERCE_MARKER (y);
+ if (FLOATP (x) || FLOATP (y))
+ return fmod_float (x, y);
/* A bignum can never be 0, so don't check that case. */
if (EQ (y, make_fixnum (0)))
xsignal0 (Qarith_error);
- return (FLOATP (x) || FLOATP (y) ? fmod_float : integer_mod) (x, y);
+ return integer_mod (x, y);
}
static Lisp_Object
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index a9d48e2..3a7462b 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -653,6 +653,13 @@ comparing the subr with a much slower lisp implementation."
(data-tests-check-sign (% -1 -3) (% nb1 nb3))
(data-tests-check-sign (mod -1 -3) (mod nb1 nb3))))
+(ert-deftest data-tests-mod-0 ()
+ (dolist (num (list (1- most-negative-fixnum) -1 0 1
+ (1+ most-positive-fixnum)))
+ (should-error (mod num 0)))
+ (when (ignore-errors (/ 0.0 0))
+ (should (equal (abs (mod 0.0 0)) (abs (- 0.0 (/ 0.0 0)))))))
+
(ert-deftest data-tests-ash-lsh ()
(should (= (ash most-negative-fixnum 1)
(* most-negative-fixnum 2)))