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 /src/floatfns.c | |
| 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 'src/floatfns.c')
| -rw-r--r-- | src/floatfns.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/floatfns.c b/src/floatfns.c index ec0349fbf40..e7d404a84e0 100644 --- a/src/floatfns.c +++ b/src/floatfns.c | |||
| @@ -435,11 +435,9 @@ emacs_rint (double d) | |||
| 435 | } | 435 | } |
| 436 | #endif | 436 | #endif |
| 437 | 437 | ||
| 438 | #ifdef HAVE_TRUNC | 438 | #ifndef HAVE_TRUNC |
| 439 | #define emacs_trunc trunc | 439 | double |
| 440 | #else | 440 | trunc (double d) |
| 441 | static double | ||
| 442 | emacs_trunc (double d) | ||
| 443 | { | 441 | { |
| 444 | return (d < 0 ? ceil : floor) (d); | 442 | return (d < 0 ? ceil : floor) (d); |
| 445 | } | 443 | } |
| @@ -482,8 +480,7 @@ Rounds ARG toward zero. | |||
| 482 | With optional DIVISOR, truncate ARG/DIVISOR. */) | 480 | With optional DIVISOR, truncate ARG/DIVISOR. */) |
| 483 | (Lisp_Object arg, Lisp_Object divisor) | 481 | (Lisp_Object arg, Lisp_Object divisor) |
| 484 | { | 482 | { |
| 485 | return rounding_driver (arg, divisor, emacs_trunc, truncate2, | 483 | return rounding_driver (arg, divisor, trunc, truncate2, "truncate"); |
| 486 | "truncate"); | ||
| 487 | } | 484 | } |
| 488 | 485 | ||
| 489 | 486 | ||
| @@ -543,7 +540,7 @@ DEFUN ("ftruncate", Fftruncate, Sftruncate, 1, 1, 0, | |||
| 543 | { | 540 | { |
| 544 | CHECK_FLOAT (arg); | 541 | CHECK_FLOAT (arg); |
| 545 | double d = XFLOAT_DATA (arg); | 542 | double d = XFLOAT_DATA (arg); |
| 546 | d = emacs_trunc (d); | 543 | d = trunc (d); |
| 547 | return make_float (d); | 544 | return make_float (d); |
| 548 | } | 545 | } |
| 549 | 546 | ||