bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optimize three-valued comparison between integers


From: Paul Eggert
Subject: Re: Optimize three-valued comparison between integers
Date: Thu, 30 Jul 2020 15:11:56 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

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. 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.

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.

Still another possibility would be to restrict _GL_CMP's arguments to integers, but I could see uses of that macro on non-NaN floating-point values (though Emacs doesn't happen to have any such uses now).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]