aboutsummaryrefslogtreecommitdiffstats
path: root/test/src/floatfns-tests.el
diff options
context:
space:
mode:
authorPaul Eggert2018-08-21 19:23:45 -0700
committerPaul Eggert2018-08-21 19:24:38 -0700
commit30efb8ed6c0968ca486081112f8d4dc147af9e6c (patch)
treefa69cc32da7a493898e62d6d00e15326f7bedf07 /test/src/floatfns-tests.el
parentc79444c5b7b8ead1ea98ed5603bf2a49c13dbf16 (diff)
downloademacs-30efb8ed6c0968ca486081112f8d4dc147af9e6c.tar.gz
emacs-30efb8ed6c0968ca486081112f8d4dc147af9e6c.zip
Add bignum support to floor, ceiling, etc.
Problem reported by Andy Moreton (Bug#32463#35 (d)). * src/floatfns.c (rounding_driver): Change the signature of the integer rounder to use mpz_t rather than EMACS_INT. All uses changed. Support bignums. (ceiling2, floor2, truncate2, round2): Remove. All uses changed to rounddiv_q or to a GMP library function. (rounddiv_q): New function. * test/src/floatfns-tests.el (bignum-round): New test.
Diffstat (limited to 'test/src/floatfns-tests.el')
-rw-r--r--test/src/floatfns-tests.el27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el
index e4caaa1e49b..592efce359d 100644
--- a/test/src/floatfns-tests.el
+++ b/test/src/floatfns-tests.el
@@ -58,4 +58,31 @@
58(ert-deftest bignum-mod () 58(ert-deftest bignum-mod ()
59 (should (= 0 (mod (1+ most-positive-fixnum) 2.0)))) 59 (should (= 0 (mod (1+ most-positive-fixnum) 2.0))))
60 60
61(ert-deftest bignum-round ()
62 (let ((ns (list (* most-positive-fixnum most-negative-fixnum)
63 (1- most-negative-fixnum) most-negative-fixnum
64 (1+ most-negative-fixnum) -2 1 1 2
65 (1- most-positive-fixnum) most-positive-fixnum
66 (1+ most-positive-fixnum)
67 (* most-positive-fixnum most-positive-fixnum))))
68 (dolist (n ns)
69 (dolist (d ns)
70 (let ((q (/ n d))
71 (r (% n d))
72 (same-sign (eq (< n 0) (< d 0))))
73 (should (= (ceiling n d)
74 (+ q (if (and same-sign (not (zerop r))) 1 0))))
75 (should (= (floor n d)
76 (- q (if (and (not same-sign) (not (zerop r))) 1 0))))
77 (should (= (truncate n d) q))
78 (let ((cdelta (abs (- n (* d (ceiling n d)))))
79 (fdelta (abs (- n (* d (floor n d)))))
80 (rdelta (abs (- n (* d (round n d))))))
81 (should (<= rdelta cdelta))
82 (should (<= rdelta fdelta))
83 (should (if (zerop r)
84 (= 0 cdelta fdelta rdelta)
85 (or (/= cdelta fdelta)
86 (zerop (% (round n d) 2)))))))))))
87
61(provide 'floatfns-tests) 88(provide 'floatfns-tests)