Commit 5f28f0db authored by Paul Eggert's avatar Paul Eggert
Browse files

Fix bug with min and max and NaNs

* src/data.c (minmax_driver): Fix bug with (min 0 NaN), which
mistakenly yielded 0.  Also, pacify GCC in a better way.
* test/src/data-tests.el (data-tests-min): Test for the bug.
parent 37b5e661
......@@ -3010,16 +3010,16 @@ static Lisp_Object
minmax_driver (ptrdiff_t nargs, Lisp_Object *args,
enum Arith_Comparison comparison)
{
eassume (0 < nargs);
Lisp_Object accum = args[0]; /* pacify GCC */
for (ptrdiff_t argnum = 0; argnum < nargs; argnum++)
Lisp_Object accum = args[0];
CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (accum);
for (ptrdiff_t argnum = 1; argnum < nargs; argnum++)
{
Lisp_Object val = args[argnum];
CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
if (argnum == 0 || !NILP (arithcompare (val, accum, comparison)))
if (!NILP (arithcompare (val, accum, comparison)))
accum = val;
else if (FLOATP (accum) && isnan (XFLOAT_DATA (accum)))
return accum;
else if (FLOATP (val) && isnan (XFLOAT_DATA (val)))
return val;
}
return accum;
}
......
......@@ -101,7 +101,11 @@
(should (= 3 (apply #'min '(3 8 3))))
(should-error (min 9 8 'foo))
(should-error (min (make-marker)))
(should (eql 1 (min (point-min-marker) 1))))
(should (eql 1 (min (point-min-marker) 1)))
(should (isnan (min 0.0e+NaN)))
(should (isnan (min 0.0e+NaN 1 2)))
(should (isnan (min 1.0 0.0e+NaN)))
(should (isnan (min 1.0 0.0e+NaN 1.1))))
;; Bool vector tests. Compactly represent bool vectors as hex
;; strings.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment