aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorPaul Eggert2018-06-25 12:21:40 -0700
committerPaul Eggert2018-06-25 12:23:08 -0700
commitd0e2a341dd9a9a365fd311748df024ecb25b70ec (patch)
treeaa5b4e9f33777155349c3aacefece4d25199b887 /src/editfns.c
parent27a21970f6faa9baf42823f731b7842b075e86eb (diff)
downloademacs-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/editfns.c')
-rw-r--r--src/editfns.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 30d585cd018..7d032a7ca4c 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -47,6 +47,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
47#include <errno.h> 47#include <errno.h>
48#include <float.h> 48#include <float.h>
49#include <limits.h> 49#include <limits.h>
50#include <math.h>
50 51
51#ifdef HAVE_TIMEZONE_T 52#ifdef HAVE_TIMEZONE_T
52# include <sys/param.h> 53# include <sys/param.h>
@@ -4671,6 +4672,12 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
4671 { 4672 {
4672 strcpy (f - pMlen - 1, "f"); 4673 strcpy (f - pMlen - 1, "f");
4673 double x = XFLOAT_DATA (arg); 4674 double x = XFLOAT_DATA (arg);
4675
4676 /* Truncate and then convert -0 to 0, to be more
4677 consistent with %x etc.; see Bug#31938. */
4678 x = trunc (x);
4679 x = x ? x : 0;
4680
4674 sprintf_bytes = sprintf (sprintf_buf, convspec, 0, x); 4681 sprintf_bytes = sprintf (sprintf_buf, convspec, 0, x);
4675 char c0 = sprintf_buf[0]; 4682 char c0 = sprintf_buf[0];
4676 bool signedp = ! ('0' <= c0 && c0 <= '9'); 4683 bool signedp = ! ('0' <= c0 && c0 <= '9');