From: Tom Tromey Date: Thu, 5 Jul 2018 17:45:21 +0000 (-0600) Subject: Make number-to-string work for bignums X-Git-Tag: emacs-27.0.90~4598^2~31 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=23eab9a6a67604b5ebcdc99efc42fbfd3345c0b0;p=emacs.git 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. --- 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. */) char buffer[max (FLOAT_TO_STRING_BUFSIZE, INT_BUFSIZE_BOUND (EMACS_INT))]; int len; + if (BIGNUMP (number)) + { + ptrdiff_t count = SPECPDL_INDEX (); + char *str = mpz_get_str (NULL, 10, XBIGNUM (number)->value); + record_unwind_protect_ptr (xfree, str); + return unbind_to (count, make_unibyte_string (str, strlen (str))); + } + CHECK_FIXNUM_OR_FLOAT (number); 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." (should-not (fixnump (+ most-positive-fixnum 1))) (should (bignump (+ most-positive-fixnum 1)))) +(ert-deftest data-tests-number-to-string () + (let* ((s "99999999999999999999999999999") + (v (read s))) + (should (equal (number-to-string v) s)))) + ;;; data-tests.el ends here