aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tromey2018-07-05 11:45:21 -0600
committerTom Tromey2018-07-12 22:12:27 -0600
commit23eab9a6a67604b5ebcdc99efc42fbfd3345c0b0 (patch)
tree43e91de269443be121e81e69e476e46ae32089b7
parent6d4bf2cedab365411f0aedb373b63291086658e9 (diff)
downloademacs-23eab9a6a67604b5ebcdc99efc42fbfd3345c0b0.tar.gz
emacs-23eab9a6a67604b5ebcdc99efc42fbfd3345c0b0.zip
Make number-to-string work for bignums
* src/data.c (Fnumber_to_string): Handle bignum. * test/src/data-tests.el (data-tests-number-to-string): New test.
-rw-r--r--src/data.c8
-rw-r--r--test/src/data-tests.el5
2 files changed, 13 insertions, 0 deletions
diff --git a/src/data.c b/src/data.c
index b49daabe85d..18b572de977 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2756,6 +2756,14 @@ NUMBER may be an integer or a floating point number. */)
2756 char buffer[max (FLOAT_TO_STRING_BUFSIZE, INT_BUFSIZE_BOUND (EMACS_INT))]; 2756 char buffer[max (FLOAT_TO_STRING_BUFSIZE, INT_BUFSIZE_BOUND (EMACS_INT))];
2757 int len; 2757 int len;
2758 2758
2759 if (BIGNUMP (number))
2760 {
2761 ptrdiff_t count = SPECPDL_INDEX ();
2762 char *str = mpz_get_str (NULL, 10, XBIGNUM (number)->value);
2763 record_unwind_protect_ptr (xfree, str);
2764 return unbind_to (count, make_unibyte_string (str, strlen (str)));
2765 }
2766
2759 CHECK_FIXNUM_OR_FLOAT (number); 2767 CHECK_FIXNUM_OR_FLOAT (number);
2760 2768
2761 if (FLOATP (number)) 2769 if (FLOATP (number))
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index 543bb90f73f..1143028a126 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -574,4 +574,9 @@ comparing the subr with a much slower lisp implementation."
574 (should-not (fixnump (+ most-positive-fixnum 1))) 574 (should-not (fixnump (+ most-positive-fixnum 1)))
575 (should (bignump (+ most-positive-fixnum 1)))) 575 (should (bignump (+ most-positive-fixnum 1))))
576 576
577(ert-deftest data-tests-number-to-string ()
578 (let* ((s "99999999999999999999999999999")
579 (v (read s)))
580 (should (equal (number-to-string v) s))))
581
577;;; data-tests.el ends here 582;;; data-tests.el ends here