summaryrefslogtreecommitdiff
path: root/test/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-11-14 18:51:17 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2019-11-14 18:52:48 -0800
commit8b848def9bc3c4ad786670d0447a6fb396f2ff30 (patch)
treeb7343d7e0c5ae80efc702e23c0b2037c8693d96a /test/src
parent6ea1e35f6f8b89b979e660bf04bda1757c0cdff0 (diff)
downloademacs-8b848def9bc3c4ad786670d0447a6fb396f2ff30.tar.gz
Handle weird cases like (ceil 0 0.0)
* src/floatfns.c (double_integer_scale): Distinguish Inf from NaN. (rounding_driver): Handle (ceil 0 0.0) and (ceil 0 1.0e+INF). * test/src/floatfns-tests.el (special-round): Add tests for weird cases like this. Avoid crash with (floor 0 0.0) * src/floatfns.c (rounding_driver): Signal an arithmetic error if divisor is 0.0 or -0.0, instead of crashing.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/floatfns-tests.el24
1 files changed, 11 insertions, 13 deletions
diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el
index 7f1d4691bf0..0eef3de75f7 100644
--- a/test/src/floatfns-tests.el
+++ b/test/src/floatfns-tests.el
@@ -106,19 +106,17 @@
(zerop (% (round n d) 2)))))))))))
(ert-deftest special-round ()
- (let ((ns '(-1e+INF 1e+INF -1 1 -1e+NaN 1e+NaN)))
- (dolist (n ns)
- (unless (<= (abs n) 1)
- (should-error (ceiling n))
- (should-error (floor n))
- (should-error (round n))
- (should-error (truncate n)))
- (dolist (d ns)
- (unless (<= (abs (/ n d)) 1)
- (should-error (ceiling n d))
- (should-error (floor n d))
- (should-error (round n d))
- (should-error (truncate n d)))))))
+ (dolist (f '(ceiling floor round truncate))
+ (let ((ns '(-1e+INF 1e+INF -1 -0.0 0.0 0 1 -1e+NaN 1e+NaN)))
+ (dolist (n ns)
+ (if (not (<= (abs n) 1))
+ (should-error (funcall f n))
+ (should (= n (funcall f n)))
+ (dolist (d '(-1e+INF 1e+INF))
+ (should (eq 0 (funcall f n d)))))
+ (dolist (d ns)
+ (when (or (zerop d) (= (abs n) 1e+INF) (not (= n n)) (not (= d d)))
+ (should-error (funcall f n d))))))))
(ert-deftest big-round ()
(should (= (floor 54043195528445955 3)