aboutsummaryrefslogtreecommitdiffstats
path: root/test/src/floatfns-tests.el
diff options
context:
space:
mode:
authorPaul Eggert2018-08-22 19:30:24 -0700
committerPaul Eggert2018-08-22 19:30:57 -0700
commitee641b87cf220250ba89f219fb47a4406a05deb7 (patch)
tree08ff44c5197ae39b2ec0906de4bb4dcafda4677f /test/src/floatfns-tests.el
parentbe5fe6183e95f3afe3a62ec43504b99df90bc794 (diff)
downloademacs-ee641b87cf220250ba89f219fb47a4406a05deb7.tar.gz
emacs-ee641b87cf220250ba89f219fb47a4406a05deb7.zip
Fix bugs when rounding to bignums
Also, since Emacs historically reported a range error when rounding operations overflowed, do that consistently for all bignum overflows. * doc/lispref/errors.texi (Standard Errors): * doc/lispref/numbers.texi (Integer Basics): Document range errors. * src/alloc.c (range_error): Rename from integer_overflow. All uses changed. * src/floatfns.c (rounding_driver): When the result of a floating point rounding operation does not fit into a fixnum, put it into a bignum instead of always signaling an range error. * test/src/floatfns-tests.el (divide-extreme-sign): These tests now return the mathematically-correct answer instead of signaling an error. (bignum-round): Check that integers round to themselves.
Diffstat (limited to 'test/src/floatfns-tests.el')
-rw-r--r--test/src/floatfns-tests.el12
1 files changed, 8 insertions, 4 deletions
diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el
index 592efce359d..d41b08f7965 100644
--- a/test/src/floatfns-tests.el
+++ b/test/src/floatfns-tests.el
@@ -20,10 +20,10 @@
20(require 'ert) 20(require 'ert)
21 21
22(ert-deftest divide-extreme-sign () 22(ert-deftest divide-extreme-sign ()
23 (should-error (ceiling most-negative-fixnum -1.0)) 23 (should (= (ceiling most-negative-fixnum -1.0) (- most-negative-fixnum)))
24 (should-error (floor most-negative-fixnum -1.0)) 24 (should (= (floor most-negative-fixnum -1.0) (- most-negative-fixnum)))
25 (should-error (round most-negative-fixnum -1.0)) 25 (should (= (round most-negative-fixnum -1.0) (- most-negative-fixnum)))
26 (should-error (truncate most-negative-fixnum -1.0))) 26 (should (= (truncate most-negative-fixnum -1.0) (- most-negative-fixnum))))
27 27
28(ert-deftest logb-extreme-fixnum () 28(ert-deftest logb-extreme-fixnum ()
29 (should (= (logb most-negative-fixnum) (1+ (logb most-positive-fixnum))))) 29 (should (= (logb most-negative-fixnum) (1+ (logb most-positive-fixnum)))))
@@ -66,6 +66,10 @@
66 (1+ most-positive-fixnum) 66 (1+ most-positive-fixnum)
67 (* most-positive-fixnum most-positive-fixnum)))) 67 (* most-positive-fixnum most-positive-fixnum))))
68 (dolist (n ns) 68 (dolist (n ns)
69 (should (= n (ceiling n)))
70 (should (= n (floor n)))
71 (should (= n (round n)))
72 (should (= n (truncate n)))
69 (dolist (d ns) 73 (dolist (d ns)
70 (let ((q (/ n d)) 74 (let ((q (/ n d))
71 (r (% n d)) 75 (r (% n d))