From d0e2a341dd9a9a365fd311748df024ecb25b70ec Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 25 Jun 2018 12:21:40 -0700 Subject: (format "%d" F) now truncates floating F Problem reported by Paul Pogonyshev (Bug#31938). * src/editfns.c: Include math.h, for trunc. (styled_format): For %d, truncate floating-point numbers and convert -0 to 0, going back to how Emacs 26 did things. * doc/lispref/strings.texi (Formatting Strings): Document behavior of %o, %d, %x, %X on floating-point numbers. * src/floatfns.c (trunc) [!HAVE_TRUNC]: Rename from emacs_trunc and make it an extern function, so that editfns.c can use it. All callers changed. * test/src/editfns-tests.el (format-%d-float): New test. --- test/src/editfns-tests.el | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/src') diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index 1ed0bd5bbaf..c828000bb4f 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el @@ -176,6 +176,14 @@ (should-error (format "%o" -1e-37) :type 'overflow-error)) +;; Bug#31938 +(ert-deftest format-%d-float () + (should (string-equal (format "%d" -1.1) "-1")) + (should (string-equal (format "%d" -0.9) "0")) + (should (string-equal (format "%d" -0.0) "0")) + (should (string-equal (format "%d" 0.0) "0")) + (should (string-equal (format "%d" 0.9) "0")) + (should (string-equal (format "%d" 1.1) "1"))) ;;; Check format-time-string with various TZ settings. ;;; Use only POSIX-compatible TZ values, since the tests should work -- cgit v1.2.3