summaryrefslogtreecommitdiff
path: root/src/floatfns.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2018-06-25 12:21:40 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2018-06-25 12:23:08 -0700
commitd0e2a341dd9a9a365fd311748df024ecb25b70ec (patch)
treeaa5b4e9f33777155349c3aacefece4d25199b887 /src/floatfns.c
parent27a21970f6faa9baf42823f731b7842b075e86eb (diff)
downloademacs-d0e2a341dd9a9a365fd311748df024ecb25b70ec.tar.gz
(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.c13
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)
}
#endif
-#ifdef HAVE_TRUNC
-#define emacs_trunc trunc
-#else
-static double
-emacs_trunc (double d)
+#ifndef HAVE_TRUNC
+double
+trunc (double d)
{
return (d < 0 ? ceil : floor) (d);
}
@@ -482,8 +480,7 @@ Rounds ARG toward zero.
With optional DIVISOR, truncate ARG/DIVISOR. */)
(Lisp_Object arg, Lisp_Object divisor)
{
- return rounding_driver (arg, divisor, emacs_trunc, truncate2,
- "truncate");
+ return rounding_driver (arg, divisor, trunc, truncate2, "truncate");
}
@@ -543,7 +540,7 @@ DEFUN ("ftruncate", Fftruncate, Sftruncate, 1, 1, 0,
{
CHECK_FLOAT (arg);
double d = XFLOAT_DATA (arg);
- d = emacs_trunc (d);
+ d = trunc (d);
return make_float (d);
}