aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorPaul Eggert2017-03-01 12:29:37 -0800
committerPaul Eggert2017-03-01 12:47:28 -0800
commit207ee94b1d1f3cbe5ddd87a4cdfae17e5ad8419d (patch)
tree6a4d82cb85a667b9cbd38d3467e2907b18dbe938 /test/src
parentebb105054a421faff17ee11f0cbcbed87661dd11 (diff)
downloademacs-207ee94b1d1f3cbe5ddd87a4cdfae17e5ad8419d.tar.gz
emacs-207ee94b1d1f3cbe5ddd87a4cdfae17e5ad8419d.zip
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.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/editfns-tests.el3
-rw-r--r--test/src/floatfns-tests.el28
2 files changed, 31 insertions, 0 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 7b4f41aab5d..14124ef85fb 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -133,4 +133,7 @@
133 (should (string= (buffer-string) "éä\"ba÷")) 133 (should (string= (buffer-string) "éä\"ba÷"))
134 (should (equal (transpose-test-get-byte-positions 7) '(1 3 5 6 7 8 10))))) 134 (should (equal (transpose-test-get-byte-positions 7) '(1 3 5 6 7 8 10)))))
135 135
136(ert-deftest format-c-float ()
137 (should-error (format "%c" 0.5)))
138
136;;; editfns-tests.el ends here 139;;; editfns-tests.el ends here
diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el
new file mode 100644
index 00000000000..a2116a59459
--- /dev/null
+++ b/test/src/floatfns-tests.el
@@ -0,0 +1,28 @@
1;;; floatfn-tests.el --- tests for floating point operations
2
3;; Copyright 2017 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
19
20(require 'ert)
21
22(ert-deftest divide-extreme-sign ()
23 (should-error (ceiling most-negative-fixnum -1.0))
24 (should-error (floor most-negative-fixnum -1.0))
25 (should-error (round most-negative-fixnum -1.0))
26 (should-error (truncate most-negative-fixnum -1.0)))
27
28(provide 'floatfns-tests)