aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPaul Eggert2018-09-22 08:59:06 -0700
committerPaul Eggert2018-09-22 09:01:26 -0700
commit0b36041d2a528419982a19940573783ff318c0d4 (patch)
tree0b66b534356f9e4ed7cb39601f6d29492cbea104 /test
parent596ccc087c8f844f81b075da643e5c554a8de9d6 (diff)
downloademacs-0b36041d2a528419982a19940573783ff318c0d4.tar.gz
emacs-0b36041d2a528419982a19940573783ff318c0d4.zip
Round bignums consistently with other integers
* src/bignum.c (mpz_bufsize): New function. (bignum_bufsize): Use it. (mpz_get_d_rounded): New function. (bignum_to_double): Use it. * src/bignum.c (bignum_to_double): * src/data.c (bignum_arith_driver): When converting bignums to double, round instead of truncating, to be consistent with what happens with fixnums. * test/src/floatfns-tests.el (bignum-to-float): Test rounding.
Diffstat (limited to 'test')
-rw-r--r--test/src/floatfns-tests.el6
1 files changed, 6 insertions, 0 deletions
diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el
index 14576b603c0..61b1c25743d 100644
--- a/test/src/floatfns-tests.el
+++ b/test/src/floatfns-tests.el
@@ -35,6 +35,12 @@
35 (should-error (fround 0) :type 'wrong-type-argument)) 35 (should-error (fround 0) :type 'wrong-type-argument))
36 36
37(ert-deftest bignum-to-float () 37(ert-deftest bignum-to-float ()
38 ;; 122 because we want to go as big as possible to provoke a rounding error,
39 ;; but not too big: 2**122 < 10**37 < 2**123, and the C standard says
40 ;; 10**37 <= DBL_MAX so 2**122 cannot overflow as a double.
41 (let ((a (1- (ash 1 122))))
42 (should (or (eql a (1- (floor (float a))))
43 (eql a (floor (float a))))))
38 (should (eql (float (+ most-positive-fixnum 1)) 44 (should (eql (float (+ most-positive-fixnum 1))
39 (+ (float most-positive-fixnum) 1)))) 45 (+ (float most-positive-fixnum) 1))))
40 46