diff options
| author | Paul Eggert | 2018-06-25 12:21:40 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-06-25 12:23:08 -0700 |
| commit | d0e2a341dd9a9a365fd311748df024ecb25b70ec (patch) | |
| tree | aa5b4e9f33777155349c3aacefece4d25199b887 /test/src | |
| parent | 27a21970f6faa9baf42823f731b7842b075e86eb (diff) | |
| download | emacs-d0e2a341dd9a9a365fd311748df024ecb25b70ec.tar.gz emacs-d0e2a341dd9a9a365fd311748df024ecb25b70ec.zip | |
(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.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/editfns-tests.el | 8 |
1 files changed, 8 insertions, 0 deletions
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 @@ | |||
| 176 | (should-error (format "%o" -1e-37) | 176 | (should-error (format "%o" -1e-37) |
| 177 | :type 'overflow-error)) | 177 | :type 'overflow-error)) |
| 178 | 178 | ||
| 179 | ;; Bug#31938 | ||
| 180 | (ert-deftest format-%d-float () | ||
| 181 | (should (string-equal (format "%d" -1.1) "-1")) | ||
| 182 | (should (string-equal (format "%d" -0.9) "0")) | ||
| 183 | (should (string-equal (format "%d" -0.0) "0")) | ||
| 184 | (should (string-equal (format "%d" 0.0) "0")) | ||
| 185 | (should (string-equal (format "%d" 0.9) "0")) | ||
| 186 | (should (string-equal (format "%d" 1.1) "1"))) | ||
| 179 | 187 | ||
| 180 | ;;; Check format-time-string with various TZ settings. | 188 | ;;; Check format-time-string with various TZ settings. |
| 181 | ;;; Use only POSIX-compatible TZ values, since the tests should work | 189 | ;;; Use only POSIX-compatible TZ values, since the tests should work |