From: Mattias Engdegård Date: Thu, 4 Jul 2024 15:48:16 +0000 (+0200) Subject: ; * src/fns.c (fixnum_float_cmp): Explain argument constraint. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5906fc6dc9835240e48591e23e3763d8fd98cb5b;p=emacs.git ; * src/fns.c (fixnum_float_cmp): Explain argument constraint. Suggested by Pip Cet. (cherry picked from commit fa6f088a483f1f2e19863800c6215a8136288b8f) --- diff --git a/src/fns.c b/src/fns.c index 07afcada62f..22947b2649f 100644 --- a/src/fns.c +++ b/src/fns.c @@ -3012,16 +3012,18 @@ bool_vector_cmp (Lisp_Object a, Lisp_Object b) return (d & aw) ? 1 : -1; } -/* Return -1 if ab, 0 if a=b or if b is NaN. */ +/* Return -1 if ab, 0 if a=b or if b is NaN (a must be a fixnum). */ static inline int fixnum_float_cmp (EMACS_INT a, double b) { double fa = (double)a; if (fa == b) { - /* This doesn't mean that a=b because the conversion may have - rounded, but b must be an integer that fits in an EMACS_INT - and we can compare in the integer domain instead. */ + /* This doesn't mean that a=b because the conversion may have rounded. + However, b must be an integer that fits in an EMACS_INT, + because |b| ≤ 2|a| and EMACS_INT has at least one bit more than + needed to represent any fixnum. + Thus we can compare in the integer domain instead. */ EMACS_INT ib = b; /* lossless conversion */ return a < ib ? -1 : a > ib; }