Paul Eggert wrote: > On 7/23/20 3:15 PM, Bruno Haible wrote: > > + AH_VERBATIM([micro_optimizations], > > +[/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2. > > + It returns > > + 1 if n1 > n2 > > + 0 if n1 == n2 > > + -1 if n1 < n2 > > While looking into using this in Emacs I noticed that _GL_CMP (A, B) > currently > returns 0 if either A or B is a NaN.
Oh, you are applying it to floating-point numbers? Indeed, I can see that it produces jump-free code also for 'double' arguments. > I suggest that we change the documentation > comment for _GL_CMP to say specifically that the result is indeterminate if > either argument is a NaN, to make it clearer that callers should not expect > the > result to be 0 in this case. I agree. Done through the patch below. > Another possibility would be to document that the result is 0 in this case, > but > I don't see how that would be useful, as macros like _GL_CMP don't work if > arguments are not taken from a total order. Right. NaNs need special treatment in the vast majority of the cases. Bruno 2020-07-31 Bruno Haible <br...@clisp.org> _GL_CMP: Improve documentation. Reported by Paul Eggert in <https://lists.gnu.org/archive/html/bug-gnulib/2020-07/msg00188.html>. * m4/gnulib-common.m4 (gl_COMMON_BODY): Clarify what arguments can be passed. diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 57f3a78..50acc0a 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 52 +# gnulib-common.m4 serial 53 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -300,7 +300,9 @@ AC_DEFUN([gl_COMMON_BODY], [ #define _GL_ASYNC_SAFE ]) AH_VERBATIM([micro_optimizations], -[/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2. +[/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where + n1 and n2 are expressions without side effects, that evaluate to real + numbers (excluding NaN). It returns 1 if n1 > n2 0 if n1 == n2