Note: it looks like the libstdc++ has similar functions, with a templated implementation: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96526 https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=9805965e3551b66b5bd751d6076791d00cdeb137
Here's a discussion how to get nearly optimal code for this function on x86_64: https://stackoverflow.com/questions/59348310/ But your portable code appears to produce fairly decent x86_64 assembly code as well. There were a few typos, which I'm correcting like this: 2023-10-02 Bruno Haible <br...@clisp.org> totalorder, totalorderf, totalorderl: Fix some typos. * m4/totalorder.m4 (gl_FUNC_TOTALORDERF): Assign TOTALORDERF_LIBM, not TOTALORDER_LIBM. * modules/totalorder (Description): Fix copy&paste mistake. (Depends-on): Fix conditions. * modules/totalorderf (Depends-on): Likewise. * modules/totalorderl (Depends-on): Likewise. diff --git a/m4/totalorder.m4 b/m4/totalorder.m4 index 4d065dc0eb..0bbd252675 100644 --- a/m4/totalorder.m4 +++ b/m4/totalorder.m4 @@ -27,7 +27,7 @@ AC_DEFUN([gl_FUNC_TOTALORDERF] else REPLACE_TOTALORDERF=1 fi - TOTALORDER_LIBM='$(ISNANF_LIBM)']) + TOTALORDERF_LIBM='$(ISNANF_LIBM)']) AC_SUBST([TOTALORDERF_LIBM]) ]) diff --git a/modules/totalorder b/modules/totalorder index c74fa383b2..00f190c42e 100644 --- a/modules/totalorder +++ b/modules/totalorder @@ -1,5 +1,5 @@ Description: -totalorder function: total order on float +totalorder function: total order on double Files: lib/totalorder.c @@ -9,8 +9,8 @@ m4/totalorder.m4 Depends-on: math extensions -isnand [test $HAVE_TOTALORDER = 0 || test $REPLACE_TOTALORDER = 0] -signbit [test $HAVE_TOTALORDER = 0 || test $REPLACE_TOTALORDER = 0] +isnand [test $HAVE_TOTALORDER = 0 || test $REPLACE_TOTALORDER = 1] +signbit [test $HAVE_TOTALORDER = 0 || test $REPLACE_TOTALORDER = 1] configure.ac: gl_FUNC_TOTALORDER diff --git a/modules/totalorderf b/modules/totalorderf index b3fb5d99e2..ab1569c9cc 100644 --- a/modules/totalorderf +++ b/modules/totalorderf @@ -9,8 +9,8 @@ m4/totalorder.m4 Depends-on: math extensions -isnanf [test $HAVE_TOTALORDERF = 0 || test $REPLACE_TOTALORDERF = 0] -signbit [test $HAVE_TOTALORDERF = 0 || test $REPLACE_TOTALORDERF = 0] +isnanf [test $HAVE_TOTALORDERF = 0 || test $REPLACE_TOTALORDERF = 1] +signbit [test $HAVE_TOTALORDERF = 0 || test $REPLACE_TOTALORDERF = 1] configure.ac: gl_FUNC_TOTALORDERF diff --git a/modules/totalorderl b/modules/totalorderl index 407b243bb3..d684c8c69c 100644 --- a/modules/totalorderl +++ b/modules/totalorderl @@ -9,9 +9,9 @@ m4/totalorder.m4 Depends-on: math extensions -stdbool [test $HAVE_TOTALORDERL = 0 || test $REPLACE_TOTALORDERL = 0] -isnanl [test $HAVE_TOTALORDERL = 0 || test $REPLACE_TOTALORDERL = 0] -signbit [test $HAVE_TOTALORDERL = 0 || test $REPLACE_TOTALORDERL = 0] +stdbool [test $HAVE_TOTALORDERL = 0 || test $REPLACE_TOTALORDERL = 1] +isnanl [test $HAVE_TOTALORDERL = 0 || test $REPLACE_TOTALORDERL = 1] +signbit [test $HAVE_TOTALORDERL = 0 || test $REPLACE_TOTALORDERL = 1] configure.ac: gl_FUNC_TOTALORDERL