1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-02-12 02:40:34 -08:00

Fix rounding errors in <, =, etc.

* etc/NEWS: Document this.
* src/bytecode.c (exec_byte_code):
* src/data.c (arithcompare):
Do not lose information when comparing floats to integers.
* test/src/data-tests.el (data-tests-=, data-tests-<)
(data-tests->, data-tests-<=, data-tests->=):
Test this.
This commit is contained in:
Paul Eggert 2017-03-02 09:11:11 -08:00
parent d546be31a9
commit 4e2622bf0d
4 changed files with 71 additions and 42 deletions

View file

@ -992,18 +992,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
CASE (Beqlsign):
{
Lisp_Object v2 = POP, v1 = TOP;
CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1);
CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2);
bool equal;
if (FLOATP (v1) || FLOATP (v2))
{
double f1 = FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1);
double f2 = FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2);
equal = f1 == f2;
}
TOP = arithcompare (v1, v2, ARITH_EQUAL);
else
equal = XINT (v1) == XINT (v2);
TOP = equal ? Qt : Qnil;
{
CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1);
CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2);
TOP = EQ (v1, v2) ? Qt : Qnil;
}
NEXT;
}