]> git.eshelyaron.com Git - emacs.git/commit
Fix rounding error in ‘ceiling’ etc.
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 1 Mar 2017 20:29:37 +0000 (12:29 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 1 Mar 2017 20:47:28 +0000 (12:47 -0800)
commit207ee94b1d1f3cbe5ddd87a4cdfae17e5ad8419d
tree6a4d82cb85a667b9cbd38d3467e2907b18dbe938
parentebb105054a421faff17ee11f0cbcbed87661dd11
Fix rounding error in ‘ceiling’ etc.

Without this fix, (ceiling most-negative-fixnum -1.0) returns
most-negative-fixnum instead of correctly signaling range-error,
and similarly for floor, round, and truncate.
* configure.ac (trunc): Add a check, since Gnulib’s doc says
‘trunc’ is missing from MSVC 9.  The Gnulib doc says ‘trunc’ is
also missing from some other older operating systems like Solaris
9 which I know we don’t care about any more, so MSVC is the only
reason to worry about ‘trunc’ here.
* src/editfns.c (styled_format): Formatting a float with %c is now an
error.  The old code did not work in general, because FIXNUM_OVERFLOW_P
had rounding errors.  Besides, the "if (FLOATP (...))" was in there
only as a result of my misunderstanding old code that I introduced
2011.  Although %d etc. is sometimes used on floats that represent
huge UIDs or PIDs etc. that do not fit in fixnums, this cannot
happen with characters.
* src/floatfns.c (rounding_driver): Rework to do the right thing
when the intermediate result equals 2.305843009213694e+18, i.e.,
is exactly 1 greater than MOST_POSITIVE_FIXNUM on a 64-bit host.
Simplify so that only one section of code checks for overflow,
rather than two.
(double_identity): Remove.  All uses changed to ...
(emacs_trunc): ... this new function.  Add replacement for
platforms that lack ‘trunc’.
* src/lisp.h (FIXNUM_OVERFLOW_P, make_fixnum_or_float):
Make it clear that the arg cannot be floating point.
* test/src/editfns-tests.el (format-c-float): New test.
* test/src/floatfns-tests.el: New file, to test for this bug.
configure.ac
src/editfns.c
src/floatfns.c
src/lisp.h
test/src/editfns-tests.el
test/src/floatfns-tests.el [new file with mode: 0644]