From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id AC6251F44D for ; Fri, 19 Apr 2024 00:29:25 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=clisp.org header.i=@clisp.org header.a=rsa-sha256 header.s=strato-dkim-0002 header.b=B7S6sMYS; dkim=fail reason="signature verification failed" header.d=clisp.org header.i=@clisp.org header.a=ed25519-sha256 header.s=strato-dkim-0003 header.b=8kmcuMGH; dkim-atps=neutral Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rxc7l-0002eB-EH; Thu, 18 Apr 2024 20:29:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxc7j-0002dz-Q8 for bug-gnulib@gnu.org; Thu, 18 Apr 2024 20:29:03 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxc7d-0006C9-5h for bug-gnulib@gnu.org; Thu, 18 Apr 2024 20:29:03 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1713486535; cv=none; d=strato.com; s=strato-dkim-0002; b=TuWt6oj/S1jkbEoNQesO7sRozPYQll8EBGRnM6kEcpzl1zQUtK/N1FtUNhR/5dZMR/ 1w4ZGLu7IWULZ2SGcqdeeqz3ZTgWKgbG+ZkyNVwwdmxn1jGGtEhzxpmuMBfLyE7tjOmG 9Ho+i0o+72eoBMagIdxit/KKdPA06biUUty41SgRl5/NmZGDc3XPc5HaL0kfjwPxnxGT vfVCYBxYqhMrQiaeYFTzRj3Il8V33tEGZCcV+OgtO8c8r+lULPRjCSyH+1k2aEv3rw8J P/J5H3fLvGqwNuizrkfUnEYsGdzEugWCgMn3e+egIPm9GCTTZMENp7kgtDP3x5UMpk3J 4dtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1713486535; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=g/sqBea+cy995HN2QwXZS8tQhjvvkJCuOTFz+ADiSOY=; b=qn51Gd+xpzJL9wR3FbiDVZgaXWFuDwLsQDTO9SKg9A+H/ksbwxjo82FY5/usAnwDD9 zQtKd2cs4ndWCkrBN0TpifjqXpsnhsPe3kDk2SMZlAzhWXZIpnS66BtY4NV06d9QlZk0 ZzCBrnoIbw7z5KJAH9tstH++qYhH96X8sdijJBNRTxNTJX8abP/CkrPltO8dk6+LB+3i qIyeK8V7glFdnZTkz/aF1+lCjxNGVzcR0VHK0LM77W0ioJqaH14LJv5zQ21KfyC0SaZh cDkzzE5kgTVaGLD7qmtvR0eICiJCbJ1i6Sr9jOjWk8T1501DBexGmfNQg+oH/qdu8/VU 5dWw== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1713486535; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=g/sqBea+cy995HN2QwXZS8tQhjvvkJCuOTFz+ADiSOY=; b=B7S6sMYSGFT5dXa/4QuXkY9flx3THHkLG7295Wr0/MJ9ipoKMJc+YFoc9A0gRbJwX/ 3fE9eDWpih475aggE4ZygmoKNqRJ/Vr6L4hidi4g1cT0WW8gyvQ68ToDH6wA0jr3GDDj IufR0blI/uaujzD0OgmUE5Q2sLEVPE91z98d9ln/gPBHzLxB3eZBdKBj4b5ikzgCEiWw HhSq9sFqfky565oatalLWei1CAPl+2Xxa6awIgBiDo9L09JC8kDF4jU9EiqByBwSIq/X fCxYPILLXC5ypxbEQrlDLNgtHDmPog8n/mujKCEsbKGXSYWfX1nVPqGz0MNfkiIa46Wu kgWQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1713486535; s=strato-dkim-0003; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=g/sqBea+cy995HN2QwXZS8tQhjvvkJCuOTFz+ADiSOY=; b=8kmcuMGHdjRccU7zDNOS0rWrQkE7p3UEacDx5i14BCwYUVSW1WJtcbblMyc1FbxQhz 5o5BqtYgtkxxpxDxJTDw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpPF3v3Fkyc3bh8pUCptnblrU1KXgQ==" Received: from nimes.localnet by smtp.strato.de (RZmta 50.3.2 AUTH) with ESMTPSA id N8610003J0Ss1PJ (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Fri, 19 Apr 2024 02:28:54 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: new modules totalordermag, totalordermagf, totalordermagl Date: Fri, 19 Apr 2024 02:28:54 +0200 Message-ID: <11994147.iFBhIDhphR@nimes> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart16083472.XhxsbSUPYR" Content-Transfer-Encoding: 7Bit Received-SPF: none client-ip=85.215.255.25; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org This is a multi-part message in MIME format. --nextPart16083472.XhxsbSUPYR Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" The ISO C 23 annex F also specifies functions for ordering numbers according to their absolute value: totalordermag totalordermagf totalordermagl So far, only glibc has these functions. This patch series implements them in Gnulib. 2024-04-18 Bruno Haible totalordermagl: Add tests. * tests/test-totalordermagl.c: New file, based on tests/test-totalorderl.c. * modules/totalordermagl-tests: New file, based on modules/totalorderl-tests. totalordermagl: New module. * lib/math.in.h (totalordermagl): New declaration. * lib/totalordermagl.c: New file, based on lib/totalorderl.c. * m4/math_h.m4 (gl_MATH_H): Test whether totalordermagl is declared. (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOTALORDERMAGL. (gl_MATH_H_DEFAULTS): Initialize HAVE_TOTALORDERMAGL, REPLACE_TOTALORDERMAGL. * modules/math (Makefile.am): Substitute GNULIB_TOTALORDERMAGL, HAVE_TOTALORDERMAGL, REPLACE_TOTALORDERMAGL. * modules/totalordermagl: New file, based on modules/totalorderl. * doc/posix-functions/totalordermagl.texi: Mention the new module. 2024-04-18 Bruno Haible totalordermagf: Add tests. * tests/test-totalordermagf.c: New file, based on tests/test-totalorderf.c. * modules/totalordermagf-tests: New file, based on modules/totalorderf-tests. totalordermagf: New module. * lib/math.in.h (totalordermagf): New declaration. * lib/totalordermagf.c: New file, based on lib/totalorderf.c. * m4/math_h.m4 (gl_MATH_H): Test whether totalordermagf is declared. (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOTALORDERMAGF. (gl_MATH_H_DEFAULTS): Initialize HAVE_TOTALORDERMAGF, REPLACE_TOTALORDERMAGF. * modules/math (Makefile.am): Substitute GNULIB_TOTALORDERMAGF, HAVE_TOTALORDERMAGF, REPLACE_TOTALORDERMAGF. * modules/totalordermagf: New file, based on modules/totalorderf. * doc/posix-functions/totalordermagf.texi: Mention the new module. 2024-04-18 Bruno Haible totalordermag: Add tests. * tests/test-totalordermag.c: New file, based on tests/test-totalorder.c. * tests/test-totalordermag.h: New file, based on tests/test-totalorder.h. * modules/totalordermag-tests: New file, based on modules/totalorder-tests. totalordermag: New module. * lib/math.in.h (totalordermag): New declaration. * lib/totalordermag.c: New file, based on lib/totalorder.c. * m4/totalordermag.m4: New file, based on m4/totalorder.m4. * m4/math_h.m4 (gl_MATH_H): Test whether totalordermag is declared. (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOTALORDERMAG. (gl_MATH_H_DEFAULTS): Initialize HAVE_TOTALORDERMAG, REPLACE_TOTALORDERMAG. * modules/math (Makefile.am): Substitute GNULIB_TOTALORDERMAG, HAVE_TOTALORDERMAG, REPLACE_TOTALORDERMAG. * modules/totalordermag: New file, based on modules/totalorder. * doc/posix-functions/totalordermag.texi: Mention the new module. --nextPart16083472.XhxsbSUPYR Content-Disposition: attachment; filename="0001-totalordermag-New-module.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-totalordermag-New-module.patch" >From 9b5f6e60d2b6ec1d995245ff628923e5a4e5d493 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 19 Apr 2024 02:21:21 +0200 Subject: [PATCH 1/6] totalordermag: New module. * lib/math.in.h (totalordermag): New declaration. * lib/totalordermag.c: New file, based on lib/totalorder.c. * m4/totalordermag.m4: New file, based on m4/totalorder.m4. * m4/math_h.m4 (gl_MATH_H): Test whether totalordermag is declared. (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOTALORDERMAG. (gl_MATH_H_DEFAULTS): Initialize HAVE_TOTALORDERMAG, REPLACE_TOTALORDERMAG. * modules/math (Makefile.am): Substitute GNULIB_TOTALORDERMAG, HAVE_TOTALORDERMAG, REPLACE_TOTALORDERMAG. * modules/totalordermag: New file, based on modules/totalorder. * doc/posix-functions/totalordermag.texi: Mention the new module. --- ChangeLog | 15 +++ doc/posix-functions/totalordermag.texi | 10 +- lib/math.in.h | 26 +++++ lib/totalordermag.c | 95 +++++++++++++++++ m4/math_h.m4 | 8 +- m4/totalordermag.m4 | 137 +++++++++++++++++++++++++ modules/math | 3 + modules/totalordermag | 39 +++++++ 8 files changed, 326 insertions(+), 7 deletions(-) create mode 100644 lib/totalordermag.c create mode 100644 m4/totalordermag.m4 create mode 100644 modules/totalordermag diff --git a/ChangeLog b/ChangeLog index 8c90a81e0a..c2e2e40d97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2024-04-18 Bruno Haible + + totalordermag: New module. + * lib/math.in.h (totalordermag): New declaration. + * lib/totalordermag.c: New file, based on lib/totalorder.c. + * m4/totalordermag.m4: New file, based on m4/totalorder.m4. + * m4/math_h.m4 (gl_MATH_H): Test whether totalordermag is declared. + (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOTALORDERMAG. + (gl_MATH_H_DEFAULTS): Initialize HAVE_TOTALORDERMAG, + REPLACE_TOTALORDERMAG. + * modules/math (Makefile.am): Substitute GNULIB_TOTALORDERMAG, + HAVE_TOTALORDERMAG, REPLACE_TOTALORDERMAG. + * modules/totalordermag: New file, based on modules/totalorder. + * doc/posix-functions/totalordermag.texi: Mention the new module. + 2024-04-18 Bruno Haible setpayloadsig*: Support newer MIPS CPUs. diff --git a/doc/posix-functions/totalordermag.texi b/doc/posix-functions/totalordermag.texi index 49685f9e66..1e1d9154e3 100644 --- a/doc/posix-functions/totalordermag.texi +++ b/doc/posix-functions/totalordermag.texi @@ -10,14 +10,10 @@ @url{https://www.gnu.org/software/libc/manual/html_node/FP-Comparison-Functions.html}. @end ifnotinfo -Gnulib module: --- +Gnulib module: totalordermag Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on all non-glibc platforms: glibc 2.24, macOS 11.1, FreeBSD 14.0, NetBSD 10.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0. @@ -25,3 +21,7 @@ This function has a different signature on some platforms: glibc 2.30. @end itemize + +Portability problems not fixed by Gnulib: +@itemize +@end itemize diff --git a/lib/math.in.h b/lib/math.in.h index 84b743e7ab..c814d2c89e 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -3006,6 +3006,32 @@ _GL_WARN_ON_USE (totalorderl, "totalorderl is unportable - " #endif +#if @GNULIB_TOTALORDERMAG@ +# if @REPLACE_TOTALORDERMAG@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef totalordermag +# define totalordermag rpl_totalordermag +# endif +_GL_FUNCDECL_RPL (totalordermag, int, (double const *, double const *)); +_GL_CXXALIAS_RPL (totalordermag, int, (double const *, double const *)); +# else +# if !@HAVE_TOTALORDERMAG@ +_GL_FUNCDECL_SYS (totalordermag, int, (double const *, double const *)); +# endif +_GL_CXXALIAS_SYS (totalordermag, int, (double const *, double const *)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN1 (totalordermag, int, (double const *, double const *)); +# endif +#elif defined GNULIB_POSIXCHECK +# undef totalordermag +# if HAVE_RAW_DECL_TOTALORDERMAG +_GL_WARN_ON_USE (totalordermag, "totalordermag is unportable - " + "use gnulib module totalordermag for portability"); +# endif +#endif + + _GL_INLINE_HEADER_END #endif /* _@GUARD_PREFIX@_MATH_H */ diff --git a/lib/totalordermag.c b/lib/totalordermag.c new file mode 100644 index 0000000000..7a52f89342 --- /dev/null +++ b/lib/totalordermag.c @@ -0,0 +1,95 @@ +/* Total order of absolute value for 'double'. + Copyright 2023-2024 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert and Bruno Haible. */ + +#include + +/* Specification. */ +#include + +#include + +#include "verify.h" + +int +totalordermag (double const *x, double const *y) +{ + /* If one of *X, *Y is a NaN and the other isn't, the answer is easy: + the NaN is "greater" than the other argument. */ + int xn = isnand (*x); + int yn = isnand (*y); + if (!xn != !yn) + return yn; + /* If none of *X, *Y is a NaN, the '<=' operator on the absolute values + does the job, including for -Infinity and +Infinity. */ + if (!xn) + return (signbit (*x) ? - *x : *x) <= (signbit (*y) ? - *y : *y); + + /* At this point, *X and *Y are NaNs. */ + +#if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT + /* The use of a union to extract the bits of the representation of a + 'double' is safe in practice, despite of the "aliasing rules" of + C99, because the GCC docs say + "Even with '-fstrict-aliasing', type-punning is allowed, provided the + memory is accessed through the union type." + and similarly for other compilers. */ +# define NWORDS \ + ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) + union { unsigned int word[NWORDS]; unsigned long long i; double value; } + xu = {0}, yu = {0}; + +# if 0 + xu.value = *x; + yu.value = *y; +# else +# if defined __GNUC__ || defined __clang__ + /* Prevent gcc and clang from reusing the values of *x and *y (fetched above) + in optimized inlined memcpy expansions. + Seen with gcc + and with clang 16.0.6 on OpenBSD 7.5. */ + __asm__ __volatile__ ("" : : : "memory"); +# endif + /* On 32-bit x86 processors, as well as on x86_64 processors with + CC="gcc -mfpmath=387", the evaluation of *x and *y above is done through + an 'fldl' instruction, which converts a signalling NaN to a quiet NaN. See + + for details. Use memcpy to avoid this. */ + memcpy (&xu.value, x, sizeof (double)); + memcpy (&yu.value, y, sizeof (double)); +# endif + + verify (NWORDS == 2); + + return ((xu.i & ~(1ULL << (DBL_SIGNBIT_BIT + 32))) /* *X without its sign bit */ +# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_DOUBLE) || defined __sh__ + /* Invert the most significant bit of the mantissa field. + Cf. snan.h. */ + ^ (1ULL << 51) +# endif + ) <= + ((yu.i & ~(1ULL << (DBL_SIGNBIT_BIT + 32))) /* *Y without its sign bit */ +# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_DOUBLE) || defined __sh__ + /* Invert the most significant bit of the mantissa field. + Cf. snan.h. */ + ^ (1ULL << 51) +# endif + ); +#else +# error "Please port gnulib totalordermagf.c to your platform!" +#endif +} diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 217c4d225d..b28c827958 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,5 +1,5 @@ # math_h.m4 -# serial 135 +# serial 136 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -56,7 +56,8 @@ AC_DEFUN_ONCE([gl_MATH_H] setpayload setpayloadf setpayloadl setpayloadsig setpayloadsigf setpayloadsigl sinf sinl sinhf sqrtf sqrtl - tanf tanl tanhf totalorder totalorderf totalorderl trunc truncf truncl]) + tanf tanl tanhf totalorder totalorderf totalorderl totalordermag + trunc truncf truncl]) ]) # gl_MATH_MODULE_INDICATOR([modulename]) @@ -183,6 +184,7 @@ AC_DEFUN([gl_MATH_H_REQUIRE_DEFAULTS] gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDER]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERL]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERMAG]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNC]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCL]) @@ -273,6 +275,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS] HAVE_TOTALORDER=1; AC_SUBST([HAVE_TOTALORDER]) HAVE_TOTALORDERF=1; AC_SUBST([HAVE_TOTALORDERF]) HAVE_TOTALORDERL=1; AC_SUBST([HAVE_TOTALORDERL]) + HAVE_TOTALORDERMAG=1; AC_SUBST([HAVE_TOTALORDERMAG]) HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL]) HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL]) HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL]) @@ -392,6 +395,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS] REPLACE_TOTALORDER=0; AC_SUBST([REPLACE_TOTALORDER]) REPLACE_TOTALORDERF=0; AC_SUBST([REPLACE_TOTALORDERF]) REPLACE_TOTALORDERL=0; AC_SUBST([REPLACE_TOTALORDERL]) + REPLACE_TOTALORDERMAG=0; AC_SUBST([REPLACE_TOTALORDERMAG]) REPLACE_TRUNC=0; AC_SUBST([REPLACE_TRUNC]) REPLACE_TRUNCF=0; AC_SUBST([REPLACE_TRUNCF]) REPLACE_TRUNCL=0; AC_SUBST([REPLACE_TRUNCL]) diff --git a/m4/totalordermag.m4 b/m4/totalordermag.m4 new file mode 100644 index 0000000000..971ea6bf4d --- /dev/null +++ b/m4/totalordermag.m4 @@ -0,0 +1,137 @@ +# totalordermag.m4 +# serial 1 +dnl Copyright 2023-2024 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_TOTALORDERMAGF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + dnl glibc versions < 2.31 had an incompatible declaration of this function, + dnl see + AC_CACHE_CHECK([whether totalordermagf has a non-standard declaration], + [gl_cv_func_totalordermagf_incompatible], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[extern + #ifdef __cplusplus + "C" + #endif + int totalordermagf (float const *, float const *); + ]]) + ], + [gl_cv_func_totalordermagf_incompatible=no], + [gl_cv_func_totalordermagf_incompatible=yes]) + ]) + if test $gl_cv_func_totalordermagf_incompatible = yes; then + REPLACE_TOTALORDERMAGF=1 + else + gl_MATHFUNC([totalordermagf], [int], [(float const *, float const *)]) + if test $gl_cv_func_totalordermagf_no_libm != yes \ + && test $gl_cv_func_totalordermagf_in_libm != yes; then + HAVE_TOTALORDERMAGF=0 + fi + fi + if test $HAVE_TOTALORDERMAGF = 0 || test $REPLACE_TOTALORDERMAGF = 1; then + TOTALORDERMAGF_LIBM='$(ISNANF_LIBM)' + dnl Prerequisite of lib/totalordermagf.c. + gl_FLOAT_SIGN_LOCATION + gl_NAN_MIPS + fi + AC_SUBST([TOTALORDERMAGF_LIBM]) +]) + +AC_DEFUN([gl_FUNC_TOTALORDERMAG], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + dnl glibc versions < 2.31 had an incompatible declaration of this function, + dnl see + AC_CACHE_CHECK([whether totalordermag has a non-standard declaration], + [gl_cv_func_totalordermag_incompatible], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[extern + #ifdef __cplusplus + "C" + #endif + int totalordermag (double const *, double const *); + ]]) + ], + [gl_cv_func_totalordermag_incompatible=no], + [gl_cv_func_totalordermag_incompatible=yes]) + ]) + if test $gl_cv_func_totalordermag_incompatible = yes; then + REPLACE_TOTALORDERMAG=1 + else + gl_MATHFUNC([totalordermag], [int], [(double const *, double const *)]) + if test $gl_cv_func_totalordermag_no_libm != yes \ + && test $gl_cv_func_totalordermag_in_libm != yes; then + HAVE_TOTALORDERMAG=0 + fi + fi + if test $HAVE_TOTALORDERMAG = 0 || test $REPLACE_TOTALORDERMAG = 1; then + TOTALORDERMAG_LIBM='$(ISNAND_LIBM)' + dnl Prerequisite of lib/totalordermag.c. + gl_DOUBLE_SIGN_LOCATION + gl_NAN_MIPS + fi + AC_SUBST([TOTALORDERMAG_LIBM]) +]) + +AC_DEFUN([gl_FUNC_TOTALORDERMAGL], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) + + dnl glibc versions < 2.31 had an incompatible declaration of this function, + dnl see + AC_CACHE_CHECK([whether totalordermagl has a non-standard declaration], + [gl_cv_func_totalordermagl_incompatible], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[extern + #ifdef __cplusplus + "C" + #endif + int totalordermagl (long double const *, long double const *); + ]]) + ], + [gl_cv_func_totalordermagl_incompatible=no], + [gl_cv_func_totalordermagl_incompatible=yes]) + ]) + if test $gl_cv_func_totalordermagl_incompatible = yes; then + REPLACE_TOTALORDERMAGL=1 + else + gl_MATHFUNC([totalordermagl], [int], + [(long double const *, long double const *)]) + if test $gl_cv_func_totalordermagl_no_libm != yes \ + && test $gl_cv_func_totalordermagl_in_libm != yes; then + HAVE_TOTALORDERMAGL=0 + fi + fi + if test $HAVE_TOTALORDERMAGL = 0 || test $REPLACE_TOTALORDERMAGL = 1; then + dnl Find libraries needed to link lib/totalorderl.c. + if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then + AC_REQUIRE([gl_FUNC_TOTALORDERMAG]) + TOTALORDERMAGL_LIBM="$TOTALORDERMAG_LIBM" + else + TOTALORDERMAGL_LIBM='$(ISNANL_LIBM)' + fi + dnl Prerequisite of lib/totalordermagl.c. + gl_LONG_DOUBLE_SIGN_LOCATION + gl_NAN_MIPS + fi + AC_SUBST([TOTALORDERMAGL_LIBM]) +]) diff --git a/modules/math b/modules/math index 8c853f0979..a82a77a9d0 100644 --- a/modules/math +++ b/modules/math @@ -144,6 +144,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_TOTALORDER''@/$(GNULIB_TOTALORDER)/g' \ -e 's/@''GNULIB_TOTALORDERF''@/$(GNULIB_TOTALORDERF)/g' \ -e 's/@''GNULIB_TOTALORDERL''@/$(GNULIB_TOTALORDERL)/g' \ + -e 's/@''GNULIB_TOTALORDERMAG''@/$(GNULIB_TOTALORDERMAG)/g' \ -e 's/@''GNULIB_MDA_J0''@/$(GNULIB_MDA_J0)/g' \ -e 's/@''GNULIB_MDA_J1''@/$(GNULIB_MDA_J1)/g' \ -e 's/@''GNULIB_MDA_JN''@/$(GNULIB_MDA_JN)/g' \ @@ -224,6 +225,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_TOTALORDER''@|$(HAVE_TOTALORDER)|g' \ -e 's|@''HAVE_TOTALORDERF''@|$(HAVE_TOTALORDERF)|g' \ -e 's|@''HAVE_TOTALORDERL''@|$(HAVE_TOTALORDERL)|g' \ + -e 's|@''HAVE_TOTALORDERMAG''@|$(HAVE_TOTALORDERMAG)|g' \ < $@-t2 > $@-t3 $(AM_V_at)sed \ -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \ @@ -350,6 +352,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_TOTALORDER''@|$(REPLACE_TOTALORDER)|g' \ -e 's|@''REPLACE_TOTALORDERF''@|$(REPLACE_TOTALORDERF)|g' \ -e 's|@''REPLACE_TOTALORDERL''@|$(REPLACE_TOTALORDERL)|g' \ + -e 's|@''REPLACE_TOTALORDERMAG''@|$(REPLACE_TOTALORDERMAG)|g' \ -e 's|@''REPLACE_TRUNC''@|$(REPLACE_TRUNC)|g' \ -e 's|@''REPLACE_TRUNCF''@|$(REPLACE_TRUNCF)|g' \ -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \ diff --git a/modules/totalordermag b/modules/totalordermag new file mode 100644 index 0000000000..d5fbe620b5 --- /dev/null +++ b/modules/totalordermag @@ -0,0 +1,39 @@ +Description: +totalordermag function: total order of absolute value on double + +Files: +lib/totalordermag.c +m4/mathfunc.m4 +m4/totalordermag.m4 +m4/nan-mips.m4 +m4/signbit.m4 + +Depends-on: +math +extensions +verify [test $HAVE_TOTALORDERMAG = 0 || test $REPLACE_TOTALORDERMAG = 1] +isnand [test $HAVE_TOTALORDERMAG = 0 || test $REPLACE_TOTALORDERMAG = 1] +signbit [test $HAVE_TOTALORDERMAG = 0 || test $REPLACE_TOTALORDERMAG = 1] + +configure.ac: +gl_FUNC_TOTALORDERMAG +gl_CONDITIONAL([GL_COND_OBJ_TOTALORDERMAG], + [test $HAVE_TOTALORDERMAG = 0 || test $REPLACE_TOTALORDERMAG = 1]) +gl_MATH_MODULE_INDICATOR([totalordermag]) + +Makefile.am: +if GL_COND_OBJ_TOTALORDERMAG +lib_SOURCES += totalordermag.c +endif + +Include: + + +Link: +$(TOTALORDERMAG_LIBM) + +License: +LGPL + +Maintainer: +all -- 2.34.1 --nextPart16083472.XhxsbSUPYR Content-Disposition: attachment; filename="0002-totalordermag-Add-tests.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0002-totalordermag-Add-tests.patch" >From a92fbf1256ed2e17ffb108d7962696e4a8a35a56 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 19 Apr 2024 02:21:34 +0200 Subject: [PATCH 2/6] totalordermag: Add tests. * tests/test-totalordermag.c: New file, based on tests/test-totalorder.c. * tests/test-totalordermag.h: New file, based on tests/test-totalorder.h. * modules/totalordermag-tests: New file, based on modules/totalorder-tests. --- ChangeLog | 8 ++++ modules/totalordermag-tests | 19 +++++++++ tests/test-totalordermag.c | 33 +++++++++++++++ tests/test-totalordermag.h | 82 +++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 modules/totalordermag-tests create mode 100644 tests/test-totalordermag.c create mode 100644 tests/test-totalordermag.h diff --git a/ChangeLog b/ChangeLog index c2e2e40d97..8ddc7cf6ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2024-04-18 Bruno Haible + totalordermag: Add tests. + * tests/test-totalordermag.c: New file, based on + tests/test-totalorder.c. + * tests/test-totalordermag.h: New file, based on + tests/test-totalorder.h. + * modules/totalordermag-tests: New file, based on + modules/totalorder-tests. + totalordermag: New module. * lib/math.in.h (totalordermag): New declaration. * lib/totalordermag.c: New file, based on lib/totalorder.c. diff --git a/modules/totalordermag-tests b/modules/totalordermag-tests new file mode 100644 index 0000000000..da45992e66 --- /dev/null +++ b/modules/totalordermag-tests @@ -0,0 +1,19 @@ +Files: +tests/test-totalordermag.c +tests/test-totalordermag.h +tests/minus-zero.h +tests/infinity.h +tests/signature.h +tests/macros.h + +Depends-on: +signed-nan +signed-snan +setpayload + +configure.ac: + +Makefile.am: +TESTS += test-totalordermag +check_PROGRAMS += test-totalordermag +test_totalordermag_LDADD = $(LDADD) @TOTALORDERMAG_LIBM@ $(SETPAYLOAD_LIBM) diff --git a/tests/test-totalordermag.c b/tests/test-totalordermag.c new file mode 100644 index 0000000000..5b2c4c70d9 --- /dev/null +++ b/tests/test-totalordermag.c @@ -0,0 +1,33 @@ +/* Test totalordermag. + Copyright 2023-2024 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include "signature.h" +SIGNATURE_CHECK (totalordermag, int, (const double *, const double *)); + +#define TOTALORDER totalordermag +#define TOTALORDER_TYPE memory_double +#define TOTALORDER_INF Infinityd +#define TOTALORDER_MINUS_ZERO minus_zerod +#define TOTALORDER_SETPAYLOAD setpayload +#define TOTALORDER_HAVE_SNAN HAVE_SNAND +#define TOTALORDER_POSITIVE_SNAN memory_positive_SNaNd +#define TOTALORDER_NEGATIVE_SNAN memory_negative_SNaNd +#include "test-totalordermag.h" diff --git a/tests/test-totalordermag.h b/tests/test-totalordermag.h new file mode 100644 index 0000000000..4d4746fae1 --- /dev/null +++ b/tests/test-totalordermag.h @@ -0,0 +1,82 @@ +/* Test a totalordermag-like function. + Copyright 2023-2024 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include +#include "infinity.h" +#include "macros.h" +#include "minus-zero.h" +#include "signed-nan.h" +#include "signed-snan.h" + +static TOTALORDER_TYPE +positive_NaN_with_payload (int payload) +{ + TOTALORDER_TYPE x; + ASSERT (TOTALORDER_SETPAYLOAD (&x.value, payload) == 0); + return x; +} + +static TOTALORDER_TYPE +negative_NaN_with_payload (int payload) +{ + TOTALORDER_TYPE x; + ASSERT (TOTALORDER_SETPAYLOAD (&x.value, payload) == 0); + x.value = - x.value; + return x; +} + +int +main () +{ + TOTALORDER_TYPE x[] = + { + negative_NaN_with_payload (1729), + negative_NaN_with_payload (641), +#if TOTALORDER_HAVE_SNAN + TOTALORDER_NEGATIVE_SNAN (), +#endif + { -TOTALORDER_INF () }, + { -1e37 }, + { -1 }, + { -1e-5 }, + { TOTALORDER_MINUS_ZERO }, + { 0 }, + { 1e-5 }, + { 1 }, + { 1e37 }, + { TOTALORDER_INF () }, +#if TOTALORDER_HAVE_SNAN + TOTALORDER_POSITIVE_SNAN (), +#endif + positive_NaN_with_payload (641), + positive_NaN_with_payload (1729) + }; + int n = SIZEOF (x); + int result = 0; + + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (!(!!TOTALORDER (&x[i].value, &x[j].value) + == ((i < n / 2 ? n - 1 - i : i) <= (j < n /2 ? n - 1 - j : j)))) + { + fprintf (stderr, "Failed: i=%d j=%d\n", i, j); + result = 1; + } + + return result; +} -- 2.34.1 --nextPart16083472.XhxsbSUPYR Content-Disposition: attachment; filename="0003-totalordermagf-New-module.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0003-totalordermagf-New-module.patch" >From 5960f7654980710b11e30ad78b283cd3d9438a06 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 19 Apr 2024 02:21:56 +0200 Subject: [PATCH 3/6] totalordermagf: New module. * lib/math.in.h (totalordermagf): New declaration. * lib/totalordermagf.c: New file, based on lib/totalorderf.c. * m4/math_h.m4 (gl_MATH_H): Test whether totalordermagf is declared. (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOTALORDERMAGF. (gl_MATH_H_DEFAULTS): Initialize HAVE_TOTALORDERMAGF, REPLACE_TOTALORDERMAGF. * modules/math (Makefile.am): Substitute GNULIB_TOTALORDERMAGF, HAVE_TOTALORDERMAGF, REPLACE_TOTALORDERMAGF. * modules/totalordermagf: New file, based on modules/totalorderf. * doc/posix-functions/totalordermagf.texi: Mention the new module. --- ChangeLog | 14 ++++ doc/posix-functions/totalordermagf.texi | 10 +-- lib/math.in.h | 25 +++++++ lib/totalordermagf.c | 95 +++++++++++++++++++++++++ m4/math_h.m4 | 7 +- modules/math | 3 + modules/totalordermagf | 39 ++++++++++ 7 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 lib/totalordermagf.c create mode 100644 modules/totalordermagf diff --git a/ChangeLog b/ChangeLog index 8ddc7cf6ba..42d2c6cbc1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2024-04-18 Bruno Haible + + totalordermagf: New module. + * lib/math.in.h (totalordermagf): New declaration. + * lib/totalordermagf.c: New file, based on lib/totalorderf.c. + * m4/math_h.m4 (gl_MATH_H): Test whether totalordermagf is declared. + (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOTALORDERMAGF. + (gl_MATH_H_DEFAULTS): Initialize HAVE_TOTALORDERMAGF, + REPLACE_TOTALORDERMAGF. + * modules/math (Makefile.am): Substitute GNULIB_TOTALORDERMAGF, + HAVE_TOTALORDERMAGF, REPLACE_TOTALORDERMAGF. + * modules/totalordermagf: New file, based on modules/totalorderf. + * doc/posix-functions/totalordermagf.texi: Mention the new module. + 2024-04-18 Bruno Haible totalordermag: Add tests. diff --git a/doc/posix-functions/totalordermagf.texi b/doc/posix-functions/totalordermagf.texi index 7bec6ff62e..1bd0d56ade 100644 --- a/doc/posix-functions/totalordermagf.texi +++ b/doc/posix-functions/totalordermagf.texi @@ -10,14 +10,10 @@ @url{https://www.gnu.org/software/libc/manual/html_node/FP-Comparison-Functions.html}. @end ifnotinfo -Gnulib module: --- +Gnulib module: totalordermagf Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on all non-glibc platforms: glibc 2.24, macOS 11.1, FreeBSD 14.0, NetBSD 10.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0. @@ -25,3 +21,7 @@ This function has a different signature on some platforms: glibc 2.30. @end itemize + +Portability problems not fixed by Gnulib: +@itemize +@end itemize diff --git a/lib/math.in.h b/lib/math.in.h index c814d2c89e..43a9674fff 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -3006,6 +3006,31 @@ _GL_WARN_ON_USE (totalorderl, "totalorderl is unportable - " #endif +#if @GNULIB_TOTALORDERMAGF@ +# if @REPLACE_TOTALORDERMAGF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef totalordermagf +# define totalordermagf rpl_totalordermagf +# endif +_GL_FUNCDECL_RPL (totalordermagf, int, (float const *, float const *)); +_GL_CXXALIAS_RPL (totalordermagf, int, (float const *, float const *)); +# else +# if !@HAVE_TOTALORDERMAGF@ +_GL_FUNCDECL_SYS (totalordermagf, int, (float const *, float const *)); +# endif +_GL_CXXALIAS_SYS (totalordermagf, int, (float const *, float const *)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN1 (totalordermagf, int, (float const *, float const *)); +# endif +#elif defined GNULIB_POSIXCHECK +# undef totalordermagf +# if HAVE_RAW_DECL_TOTALORDERMAGF +_GL_WARN_ON_USE (totalordermagf, "totalordermagf is unportable - " + "use gnulib module totalordermagf for portability"); +# endif +#endif + #if @GNULIB_TOTALORDERMAG@ # if @REPLACE_TOTALORDERMAG@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/lib/totalordermagf.c b/lib/totalordermagf.c new file mode 100644 index 0000000000..07a35c9689 --- /dev/null +++ b/lib/totalordermagf.c @@ -0,0 +1,95 @@ +/* Total order of absolute value for 'float'. + Copyright 2023-2024 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert and Bruno Haible. */ + +#include + +/* Specification. */ +#include + +#include + +#include "verify.h" + +int +totalordermagf (float const *x, float const *y) +{ + /* If one of *X, *Y is a NaN and the other isn't, the answer is easy: + the NaN is "greater" than the other argument. */ + int xn = isnanf (*x); + int yn = isnanf (*y); + if (!xn != !yn) + return yn; + /* If none of *X, *Y is a NaN, the '<=' operator on the absolute values + does the job, including for -Infinity and +Infinity. */ + if (!xn) + return (signbit (*x) ? - *x : *x) <= (signbit (*y) ? - *y : *y); + + /* At this point, *X and *Y are NaNs. */ + +#if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT + /* The use of a union to extract the bits of the representation of a + 'float' is safe in practice, despite of the "aliasing rules" of + C99, because the GCC docs say + "Even with '-fstrict-aliasing', type-punning is allowed, provided the + memory is accessed through the union type." + and similarly for other compilers. */ +# define NWORDS \ + ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) + union { unsigned int word[NWORDS]; float value; } + xu = {0}, yu = {0}; + +# if 0 + xu.value = *x; + yu.value = *y; +# else +# if defined __GNUC__ || defined __clang__ + /* Prevent gcc and clang from reusing the values of *x and *y (fetched above) + in optimized inlined memcpy expansions. + Seen with gcc + and with clang 16.0.6 on OpenBSD 7.5. */ + __asm__ __volatile__ ("" : : : "memory"); +# endif + /* On 32-bit x86 processors, as well as on x86_64 processors with + CC="gcc -mfpmath=387", the evaluation of *x and *y above is done through + an 'flds' instruction, which converts a signalling NaN to a quiet NaN. See + + for details. Use memcpy to avoid this. */ + memcpy (&xu.value, x, sizeof (float)); + memcpy (&yu.value, y, sizeof (float)); +# endif + + verify (NWORDS == 1); + + return ((xu.word[0] & ~(1U << FLT_SIGNBIT_BIT)) /* *X without its sign bit */ +# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__ + /* Invert the most significant bit of the mantissa field. + Cf. snan.h. */ + ^ (1U << 22) +# endif + ) <= + ((yu.word[0] & ~(1U << FLT_SIGNBIT_BIT)) /* *Y without its sign bit */ +# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__ + /* Invert the most significant bit of the mantissa field. + Cf. snan.h. */ + ^ (1U << 22) +# endif + ); +#else +# error "Please port gnulib totalordermagf.c to your platform!" +#endif +} diff --git a/m4/math_h.m4 b/m4/math_h.m4 index b28c827958..d07813a016 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,5 +1,5 @@ # math_h.m4 -# serial 136 +# serial 137 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -57,7 +57,7 @@ AC_DEFUN_ONCE([gl_MATH_H] setpayloadsig setpayloadsigf setpayloadsigl sinf sinl sinhf sqrtf sqrtl tanf tanl tanhf totalorder totalorderf totalorderl totalordermag - trunc truncf truncl]) + totalordermagf trunc truncf truncl]) ]) # gl_MATH_MODULE_INDICATOR([modulename]) @@ -185,6 +185,7 @@ AC_DEFUN([gl_MATH_H_REQUIRE_DEFAULTS] gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERL]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERMAG]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERMAGF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNC]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCL]) @@ -276,6 +277,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS] HAVE_TOTALORDERF=1; AC_SUBST([HAVE_TOTALORDERF]) HAVE_TOTALORDERL=1; AC_SUBST([HAVE_TOTALORDERL]) HAVE_TOTALORDERMAG=1; AC_SUBST([HAVE_TOTALORDERMAG]) + HAVE_TOTALORDERMAGF=1; AC_SUBST([HAVE_TOTALORDERMAGF]) HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL]) HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL]) HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL]) @@ -396,6 +398,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS] REPLACE_TOTALORDERF=0; AC_SUBST([REPLACE_TOTALORDERF]) REPLACE_TOTALORDERL=0; AC_SUBST([REPLACE_TOTALORDERL]) REPLACE_TOTALORDERMAG=0; AC_SUBST([REPLACE_TOTALORDERMAG]) + REPLACE_TOTALORDERMAGF=0; AC_SUBST([REPLACE_TOTALORDERMAGF]) REPLACE_TRUNC=0; AC_SUBST([REPLACE_TRUNC]) REPLACE_TRUNCF=0; AC_SUBST([REPLACE_TRUNCF]) REPLACE_TRUNCL=0; AC_SUBST([REPLACE_TRUNCL]) diff --git a/modules/math b/modules/math index a82a77a9d0..04fa287209 100644 --- a/modules/math +++ b/modules/math @@ -145,6 +145,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_TOTALORDERF''@/$(GNULIB_TOTALORDERF)/g' \ -e 's/@''GNULIB_TOTALORDERL''@/$(GNULIB_TOTALORDERL)/g' \ -e 's/@''GNULIB_TOTALORDERMAG''@/$(GNULIB_TOTALORDERMAG)/g' \ + -e 's/@''GNULIB_TOTALORDERMAGF''@/$(GNULIB_TOTALORDERMAGF)/g' \ -e 's/@''GNULIB_MDA_J0''@/$(GNULIB_MDA_J0)/g' \ -e 's/@''GNULIB_MDA_J1''@/$(GNULIB_MDA_J1)/g' \ -e 's/@''GNULIB_MDA_JN''@/$(GNULIB_MDA_JN)/g' \ @@ -226,6 +227,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_TOTALORDERF''@|$(HAVE_TOTALORDERF)|g' \ -e 's|@''HAVE_TOTALORDERL''@|$(HAVE_TOTALORDERL)|g' \ -e 's|@''HAVE_TOTALORDERMAG''@|$(HAVE_TOTALORDERMAG)|g' \ + -e 's|@''HAVE_TOTALORDERMAGF''@|$(HAVE_TOTALORDERMAGF)|g' \ < $@-t2 > $@-t3 $(AM_V_at)sed \ -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \ @@ -353,6 +355,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_TOTALORDERF''@|$(REPLACE_TOTALORDERF)|g' \ -e 's|@''REPLACE_TOTALORDERL''@|$(REPLACE_TOTALORDERL)|g' \ -e 's|@''REPLACE_TOTALORDERMAG''@|$(REPLACE_TOTALORDERMAG)|g' \ + -e 's|@''REPLACE_TOTALORDERMAGF''@|$(REPLACE_TOTALORDERMAGF)|g' \ -e 's|@''REPLACE_TRUNC''@|$(REPLACE_TRUNC)|g' \ -e 's|@''REPLACE_TRUNCF''@|$(REPLACE_TRUNCF)|g' \ -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \ diff --git a/modules/totalordermagf b/modules/totalordermagf new file mode 100644 index 0000000000..0686bb4e01 --- /dev/null +++ b/modules/totalordermagf @@ -0,0 +1,39 @@ +Description: +totalordermagf function: total order of absolute value on float + +Files: +lib/totalordermagf.c +m4/mathfunc.m4 +m4/totalordermag.m4 +m4/nan-mips.m4 +m4/signbit.m4 + +Depends-on: +math +extensions +verify [test $HAVE_TOTALORDERMAGF = 0 || test $REPLACE_TOTALORDERMAGF = 1] +isnanf [test $HAVE_TOTALORDERMAGF = 0 || test $REPLACE_TOTALORDERMAGF = 1] +signbit [test $HAVE_TOTALORDERMAGF = 0 || test $REPLACE_TOTALORDERMAGF = 1] + +configure.ac: +gl_FUNC_TOTALORDERMAGF +gl_CONDITIONAL([GL_COND_OBJ_TOTALORDERMAGF], + [test $HAVE_TOTALORDERMAGF = 0 || test $REPLACE_TOTALORDERMAGF = 1]) +gl_MATH_MODULE_INDICATOR([totalordermagf]) + +Makefile.am: +if GL_COND_OBJ_TOTALORDERMAGF +lib_SOURCES += totalordermagf.c +endif + +Include: + + +Link: +$(TOTALORDERMAGF_LIBM) + +License: +LGPL + +Maintainer: +all -- 2.34.1 --nextPart16083472.XhxsbSUPYR Content-Disposition: attachment; filename="0004-totalordermagf-Add-tests.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0004-totalordermagf-Add-tests.patch" >From 52df2e93693f789c9928e0d81430588e58f40fbb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 19 Apr 2024 02:22:01 +0200 Subject: [PATCH 4/6] totalordermagf: Add tests. * tests/test-totalordermagf.c: New file, based on tests/test-totalorderf.c. * modules/totalordermagf-tests: New file, based on modules/totalorderf-tests. --- ChangeLog | 6 ++++++ modules/totalordermagf-tests | 19 +++++++++++++++++++ tests/test-totalordermagf.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 modules/totalordermagf-tests create mode 100644 tests/test-totalordermagf.c diff --git a/ChangeLog b/ChangeLog index 42d2c6cbc1..3257161de6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2024-04-18 Bruno Haible + totalordermagf: Add tests. + * tests/test-totalordermagf.c: New file, based on + tests/test-totalorderf.c. + * modules/totalordermagf-tests: New file, based on + modules/totalorderf-tests. + totalordermagf: New module. * lib/math.in.h (totalordermagf): New declaration. * lib/totalordermagf.c: New file, based on lib/totalorderf.c. diff --git a/modules/totalordermagf-tests b/modules/totalordermagf-tests new file mode 100644 index 0000000000..fd8a50f42a --- /dev/null +++ b/modules/totalordermagf-tests @@ -0,0 +1,19 @@ +Files: +tests/test-totalordermagf.c +tests/test-totalordermag.h +tests/minus-zero.h +tests/infinity.h +tests/signature.h +tests/macros.h + +Depends-on: +signed-nan +signed-snan +setpayloadf + +configure.ac: + +Makefile.am: +TESTS += test-totalordermagf +check_PROGRAMS += test-totalordermagf +test_totalordermagf_LDADD = $(LDADD) @TOTALORDERMAGF_LIBM@ $(SETPAYLOADF_LIBM) diff --git a/tests/test-totalordermagf.c b/tests/test-totalordermagf.c new file mode 100644 index 0000000000..b6ada9d59f --- /dev/null +++ b/tests/test-totalordermagf.c @@ -0,0 +1,33 @@ +/* Test totalordermagf. + Copyright 2023-2024 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include "signature.h" +SIGNATURE_CHECK (totalordermagf, int, (const float *, const float *)); + +#define TOTALORDER totalordermagf +#define TOTALORDER_TYPE memory_float +#define TOTALORDER_INF Infinityf +#define TOTALORDER_MINUS_ZERO minus_zerof +#define TOTALORDER_SETPAYLOAD setpayloadf +#define TOTALORDER_HAVE_SNAN HAVE_SNANF +#define TOTALORDER_POSITIVE_SNAN memory_positive_SNaNf +#define TOTALORDER_NEGATIVE_SNAN memory_negative_SNaNf +#include "test-totalordermag.h" -- 2.34.1 --nextPart16083472.XhxsbSUPYR Content-Disposition: attachment; filename="0005-totalordermagl-New-module.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0005-totalordermagl-New-module.patch" >From a0e8c0276ae0879a6cb07e9fd0fb83530d030c6d Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 19 Apr 2024 02:22:16 +0200 Subject: [PATCH 5/6] totalordermagl: New module. * lib/math.in.h (totalordermagl): New declaration. * lib/totalordermagl.c: New file, based on lib/totalorderl.c. * m4/math_h.m4 (gl_MATH_H): Test whether totalordermagl is declared. (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOTALORDERMAGL. (gl_MATH_H_DEFAULTS): Initialize HAVE_TOTALORDERMAGL, REPLACE_TOTALORDERMAGL. * modules/math (Makefile.am): Substitute GNULIB_TOTALORDERMAGL, HAVE_TOTALORDERMAGL, REPLACE_TOTALORDERMAGL. * modules/totalordermagl: New file, based on modules/totalorderl. * doc/posix-functions/totalordermagl.texi: Mention the new module. --- ChangeLog | 14 +++ doc/posix-functions/totalordermagl.texi | 10 +- lib/math.in.h | 30 +++++ lib/totalordermagl.c | 149 ++++++++++++++++++++++++ m4/math_h.m4 | 7 +- modules/math | 3 + modules/totalordermagl | 43 +++++++ 7 files changed, 249 insertions(+), 7 deletions(-) create mode 100644 lib/totalordermagl.c create mode 100644 modules/totalordermagl diff --git a/ChangeLog b/ChangeLog index 3257161de6..7bd8b5072d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2024-04-18 Bruno Haible + + totalordermagl: New module. + * lib/math.in.h (totalordermagl): New declaration. + * lib/totalordermagl.c: New file, based on lib/totalorderl.c. + * m4/math_h.m4 (gl_MATH_H): Test whether totalordermagl is declared. + (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_TOTALORDERMAGL. + (gl_MATH_H_DEFAULTS): Initialize HAVE_TOTALORDERMAGL, + REPLACE_TOTALORDERMAGL. + * modules/math (Makefile.am): Substitute GNULIB_TOTALORDERMAGL, + HAVE_TOTALORDERMAGL, REPLACE_TOTALORDERMAGL. + * modules/totalordermagl: New file, based on modules/totalorderl. + * doc/posix-functions/totalordermagl.texi: Mention the new module. + 2024-04-18 Bruno Haible totalordermagf: Add tests. diff --git a/doc/posix-functions/totalordermagl.texi b/doc/posix-functions/totalordermagl.texi index 45895dd1b8..09d36199f8 100644 --- a/doc/posix-functions/totalordermagl.texi +++ b/doc/posix-functions/totalordermagl.texi @@ -10,14 +10,10 @@ @url{https://www.gnu.org/software/libc/manual/html_node/FP-Comparison-Functions.html}. @end ifnotinfo -Gnulib module: --- +Gnulib module: totalordermagl Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on all non-glibc platforms: glibc 2.24, macOS 11.1, FreeBSD 14.0, NetBSD 10.0, OpenBSD 6.7, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.4, Cygwin 2.9, mingw, MSVC 14, Android 9.0. @@ -25,3 +21,7 @@ This function has a different signature on some platforms: glibc 2.30. @end itemize + +Portability problems not fixed by Gnulib: +@itemize +@end itemize diff --git a/lib/math.in.h b/lib/math.in.h index 43a9674fff..96d0da44fd 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -3056,6 +3056,36 @@ _GL_WARN_ON_USE (totalordermag, "totalordermag is unportable - " # endif #endif +#if @GNULIB_TOTALORDERMAGL@ +# if @REPLACE_TOTALORDERMAGL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef totalordermagl +# define totalordermagl rpl_totalordermagl +# endif +_GL_FUNCDECL_RPL (totalordermagl, int, + (long double const *, long double const *)); +_GL_CXXALIAS_RPL (totalordermagl, int, + (long double const *, long double const *)); +# else +# if !@HAVE_TOTALORDERMAGL@ +_GL_FUNCDECL_SYS (totalordermagl, int, + (long double const *, long double const *)); +# endif +_GL_CXXALIAS_SYS (totalordermagl, int, + (long double const *, long double const *)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN1 (totalordermagl, int, + (long double const *, long double const *)); +# endif +#elif defined GNULIB_POSIXCHECK +# undef totalordermagl +# if HAVE_RAW_DECL_TOTALORDERMAGL +_GL_WARN_ON_USE (totalordermagl, "totalordermagl is unportable - " + "use gnulib module totalordermagl for portability"); +# endif +#endif + _GL_INLINE_HEADER_END diff --git a/lib/totalordermagl.c b/lib/totalordermagl.c new file mode 100644 index 0000000000..85d492f066 --- /dev/null +++ b/lib/totalordermagl.c @@ -0,0 +1,149 @@ +/* Total order of absolute value for 'long double'. + Copyright 2023-2024 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This file is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert and Bruno Haible. */ + +#include + +/* Specification. */ +#include + +#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE + +int +totalordermagl (long double const *x, long double const *y) +{ + return totalordermag ((double const *) x, (double const *) y); +} + +#else + +# include +# include +# include + +# include "verify.h" + +int +totalordermagl (long double const *x, long double const *y) +{ + /* If one of *X, *Y is a NaN and the other isn't, the answer is easy: + the NaN is "greater" than the other argument. */ + int xn = isnanl (*x); + int yn = isnanl (*y); + if (!xn != !yn) + return yn; + /* If none of *X, *Y is a NaN, the '<=' operator on the absolute values + does the job, including for -Infinity and +Infinity. */ + if (!xn) + return (signbit (*x) ? - *x : *x) <= (signbit (*y) ? - *y : *y); + + /* At this point, *X and *Y are NaNs. */ + +# if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT + /* The use of a union to extract the bits of the representation of a + 'double' is safe in practice, despite of the "aliasing rules" of + C99, because the GCC docs say + "Even with '-fstrict-aliasing', type-punning is allowed, provided the + memory is accessed through the union type." + and similarly for other compilers. */ +# define NWORDS \ + ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) +# if LDBL_MANT_DIG == 64 /* on i386, x86_64, ia64, m68k */ + /* A single uint64_t is enough to hold the payload, since we ignore the sign + bit and the exponent has the maximum possible value. */ + verify (NWORDS >= 3); +# if LDBL_SIGNBIT_WORD == 2 && LDBL_SIGNBIT_BIT == 15 /* on i386, x86_64, ia64 */ + /* Also, LDBL_EXPBIT0_WORD == 2 && LDBL_EXPBIT0_BIT == 0. */ + union { unsigned int word[NWORDS]; uint64_t i; long double value; } xu, yu; + xu.value = *x; + yu.value = *y; + return xu.i <= yu.i; +# elif LDBL_SIGNBIT_WORD == 0 && LDBL_SIGNBIT_BIT == 31 /* on m68k */ + /* Also, LDBL_EXPBIT0_WORD == 0 && LDBL_EXPBIT0_BIT == 16. */ + union { unsigned int word[NWORDS]; long double value; } xu, yu; + xu.value = *x; + yu.value = *y; + /* The payload is in word[1] (high part) and word[2] (low part). */ + return (xu.word[1] < yu.word[1]) + | ((xu.word[1] == yu.word[1]) & (xu.word[2] <= yu.word[2])); +# else +# error "Please port gnulib totalordermagl.c to your platform!" +# endif +# elif LDBL_MANT_DIG == 106 /* on powerpc, powerpc64, powerpc64le */ + /* Two uint64_t are needed to hold the payload. + In the double-double representation, each of the two uint64_t holds + a sign bit. */ + verify (NWORDS == 4); + union { unsigned int word[NWORDS]; uint64_t i[2]; long double value; } + xu = {0}, yu = {0}; + xu.value = *x; + yu.value = *y; + uint64_t xhi = xu.i[0] & ~((uint64_t) 1 << (LDBL_SIGNBIT_BIT + 32)); + uint64_t xlo = xu.i[1] & ~((uint64_t) 1 << (LDBL_SIGNBIT_BIT + 32)); + uint64_t yhi = yu.i[0] & ~((uint64_t) 1 << (LDBL_SIGNBIT_BIT + 32)); + uint64_t ylo = yu.i[1] & ~((uint64_t) 1 << (LDBL_SIGNBIT_BIT + 32)); + return (xhi < yhi) | ((xhi == yhi) & (xlo <= ylo)); +# else + /* Here, LDBL_MANT_DIG == 113 (alpha, arm64, loongarch64, mips64, riscv64, + s390x, sparc64). */ + /* Two uint64_t are needed to hold the payload. */ + verify (NWORDS == 4); + union { unsigned int word[NWORDS]; uint64_t i[2]; long double value; } + xu = {0}, yu = {0}; +# if 0 + xu.value = *x; + yu.value = *y; +# else + /* On Linux/SPARC in 64-bit mode, gcc-6.4.0 -O2 miscompiles the simple + assignments above. Use memcpy as a workaround. */ + memcpy (&xu.value, x, sizeof (long double)); + memcpy (&yu.value, y, sizeof (long double)); +# endif + uint64_t xhi; + uint64_t xlo; + uint64_t yhi; + uint64_t ylo; +# if LDBL_SIGNBIT_WORD < 2 /* big-endian */ + xhi = xu.i[0] & ~((uint64_t) 1 << (LDBL_SIGNBIT_BIT + 32 * (1 - LDBL_SIGNBIT_WORD))); + xlo = xu.i[1]; + yhi = yu.i[0] & ~((uint64_t) 1 << (LDBL_SIGNBIT_BIT + 32 * (1 - LDBL_SIGNBIT_WORD))); + ylo = yu.i[1]; +# else /* little-endian */ + xhi = xu.i[1] & ~((uint64_t) 1 << (LDBL_SIGNBIT_BIT + 32 * (LDBL_SIGNBIT_WORD - 2))); + xlo = xu.i[0]; + yhi = yu.i[1] & ~((uint64_t) 1 << (LDBL_SIGNBIT_BIT + 32 * (LDBL_SIGNBIT_WORD - 2))); + ylo = yu.i[0]; +# endif +# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_LONG_DOUBLE) || defined __sh__ + /* Invert the most significant bit of the mantissa field. Cf. snan.h. */ + xhi ^= + (1ULL << (LDBL_MANT_DIG == 106 + ? 51 /* double-double representation */ + : (LDBL_MANT_DIG - 2) - 64)); /* quad precision representation */ + yhi ^= + (1ULL << (LDBL_MANT_DIG == 106 + ? 51 /* double-double representation */ + : (LDBL_MANT_DIG - 2) - 64)); /* quad precision representation */ +# endif + return (xhi < yhi) | ((xhi == yhi) & (xlo <= ylo)); +# endif +# else +# error "Please port gnulib totalordermagl.c to your platform!" +# endif +} + +#endif diff --git a/m4/math_h.m4 b/m4/math_h.m4 index d07813a016..4b26c9e9dc 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,5 +1,5 @@ # math_h.m4 -# serial 137 +# serial 138 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -57,7 +57,7 @@ AC_DEFUN_ONCE([gl_MATH_H] setpayloadsig setpayloadsigf setpayloadsigl sinf sinl sinhf sqrtf sqrtl tanf tanl tanhf totalorder totalorderf totalorderl totalordermag - totalordermagf trunc truncf truncl]) + totalordermagf totalordermagl trunc truncf truncl]) ]) # gl_MATH_MODULE_INDICATOR([modulename]) @@ -186,6 +186,7 @@ AC_DEFUN([gl_MATH_H_REQUIRE_DEFAULTS] gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERL]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERMAG]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERMAGF]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TOTALORDERMAGL]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNC]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCL]) @@ -278,6 +279,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS] HAVE_TOTALORDERL=1; AC_SUBST([HAVE_TOTALORDERL]) HAVE_TOTALORDERMAG=1; AC_SUBST([HAVE_TOTALORDERMAG]) HAVE_TOTALORDERMAGF=1; AC_SUBST([HAVE_TOTALORDERMAGF]) + HAVE_TOTALORDERMAGL=1; AC_SUBST([HAVE_TOTALORDERMAGL]) HAVE_DECL_ACOSL=1; AC_SUBST([HAVE_DECL_ACOSL]) HAVE_DECL_ASINL=1; AC_SUBST([HAVE_DECL_ASINL]) HAVE_DECL_ATANL=1; AC_SUBST([HAVE_DECL_ATANL]) @@ -399,6 +401,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS] REPLACE_TOTALORDERL=0; AC_SUBST([REPLACE_TOTALORDERL]) REPLACE_TOTALORDERMAG=0; AC_SUBST([REPLACE_TOTALORDERMAG]) REPLACE_TOTALORDERMAGF=0; AC_SUBST([REPLACE_TOTALORDERMAGF]) + REPLACE_TOTALORDERMAGL=0; AC_SUBST([REPLACE_TOTALORDERMAGL]) REPLACE_TRUNC=0; AC_SUBST([REPLACE_TRUNC]) REPLACE_TRUNCF=0; AC_SUBST([REPLACE_TRUNCF]) REPLACE_TRUNCL=0; AC_SUBST([REPLACE_TRUNCL]) diff --git a/modules/math b/modules/math index 04fa287209..983c7bf91e 100644 --- a/modules/math +++ b/modules/math @@ -146,6 +146,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_TOTALORDERL''@/$(GNULIB_TOTALORDERL)/g' \ -e 's/@''GNULIB_TOTALORDERMAG''@/$(GNULIB_TOTALORDERMAG)/g' \ -e 's/@''GNULIB_TOTALORDERMAGF''@/$(GNULIB_TOTALORDERMAGF)/g' \ + -e 's/@''GNULIB_TOTALORDERMAGL''@/$(GNULIB_TOTALORDERMAGL)/g' \ -e 's/@''GNULIB_MDA_J0''@/$(GNULIB_MDA_J0)/g' \ -e 's/@''GNULIB_MDA_J1''@/$(GNULIB_MDA_J1)/g' \ -e 's/@''GNULIB_MDA_JN''@/$(GNULIB_MDA_JN)/g' \ @@ -228,6 +229,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_TOTALORDERL''@|$(HAVE_TOTALORDERL)|g' \ -e 's|@''HAVE_TOTALORDERMAG''@|$(HAVE_TOTALORDERMAG)|g' \ -e 's|@''HAVE_TOTALORDERMAGF''@|$(HAVE_TOTALORDERMAGF)|g' \ + -e 's|@''HAVE_TOTALORDERMAGL''@|$(HAVE_TOTALORDERMAGL)|g' \ < $@-t2 > $@-t3 $(AM_V_at)sed \ -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \ @@ -356,6 +358,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_TOTALORDERL''@|$(REPLACE_TOTALORDERL)|g' \ -e 's|@''REPLACE_TOTALORDERMAG''@|$(REPLACE_TOTALORDERMAG)|g' \ -e 's|@''REPLACE_TOTALORDERMAGF''@|$(REPLACE_TOTALORDERMAGF)|g' \ + -e 's|@''REPLACE_TOTALORDERMAGL''@|$(REPLACE_TOTALORDERMAGL)|g' \ -e 's|@''REPLACE_TRUNC''@|$(REPLACE_TRUNC)|g' \ -e 's|@''REPLACE_TRUNCF''@|$(REPLACE_TRUNCF)|g' \ -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \ diff --git a/modules/totalordermagl b/modules/totalordermagl new file mode 100644 index 0000000000..ca51cd09bc --- /dev/null +++ b/modules/totalordermagl @@ -0,0 +1,43 @@ +Description: +totalordermagl function: total order of absolute value on long double + +Files: +lib/totalordermagl.c +m4/mathfunc.m4 +m4/totalordermag.m4 +m4/nan-mips.m4 +m4/signbit.m4 + +Depends-on: +math +extensions +totalordermag [{ test $HAVE_TOTALORDERMAGL = 0 || test $REPLACE_TOTALORDERMAGL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +float [{ test $HAVE_TOTALORDERMAGL = 0 || test $REPLACE_TOTALORDERMAGL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +stdbool [{ test $HAVE_TOTALORDERMAGL = 0 || test $REPLACE_TOTALORDERMAGL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +stdint [{ test $HAVE_TOTALORDERMAGL = 0 || test $REPLACE_TOTALORDERMAGL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +verify [{ test $HAVE_TOTALORDERMAGL = 0 || test $REPLACE_TOTALORDERMAGL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +isnanl [{ test $HAVE_TOTALORDERMAGL = 0 || test $REPLACE_TOTALORDERMAGL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +signbit [{ test $HAVE_TOTALORDERMAGL = 0 || test $REPLACE_TOTALORDERMAGL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] + +configure.ac: +gl_FUNC_TOTALORDERMAGL +gl_CONDITIONAL([GL_COND_OBJ_TOTALORDERMAGL], + [test $HAVE_TOTALORDERMAGL = 0 || test $REPLACE_TOTALORDERMAGL = 1]) +gl_MATH_MODULE_INDICATOR([totalordermagl]) + +Makefile.am: +if GL_COND_OBJ_TOTALORDERMAGL +lib_SOURCES += totalordermagl.c +endif + +Include: + + +Link: +$(TOTALORDERMAGL_LIBM) + +License: +LGPL + +Maintainer: +all -- 2.34.1 --nextPart16083472.XhxsbSUPYR Content-Disposition: attachment; filename="0006-totalordermagl-Add-tests.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0006-totalordermagl-Add-tests.patch" >From abd0b89dbbd77085d1d10f421d521a919b14ebd7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 19 Apr 2024 02:22:21 +0200 Subject: [PATCH 6/6] totalordermagl: Add tests. * tests/test-totalordermagl.c: New file, based on tests/test-totalorderl.c. * modules/totalordermagl-tests: New file, based on modules/totalorderl-tests. --- ChangeLog | 6 ++++++ modules/totalordermagl-tests | 19 +++++++++++++++++++ tests/test-totalordermagl.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 modules/totalordermagl-tests create mode 100644 tests/test-totalordermagl.c diff --git a/ChangeLog b/ChangeLog index 7bd8b5072d..7ce75a98a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2024-04-18 Bruno Haible + totalordermagl: Add tests. + * tests/test-totalordermagl.c: New file, based on + tests/test-totalorderl.c. + * modules/totalordermagl-tests: New file, based on + modules/totalorderl-tests. + totalordermagl: New module. * lib/math.in.h (totalordermagl): New declaration. * lib/totalordermagl.c: New file, based on lib/totalorderl.c. diff --git a/modules/totalordermagl-tests b/modules/totalordermagl-tests new file mode 100644 index 0000000000..fe6b6e0a26 --- /dev/null +++ b/modules/totalordermagl-tests @@ -0,0 +1,19 @@ +Files: +tests/test-totalordermagl.c +tests/test-totalordermag.h +tests/minus-zero.h +tests/infinity.h +tests/signature.h +tests/macros.h + +Depends-on: +signed-nan +signed-snan +setpayloadl + +configure.ac: + +Makefile.am: +TESTS += test-totalordermagl +check_PROGRAMS += test-totalordermagl +test_totalordermagl_LDADD = $(LDADD) @TOTALORDERMAGL_LIBM@ $(SETPAYLOADL_LIBM) diff --git a/tests/test-totalordermagl.c b/tests/test-totalordermagl.c new file mode 100644 index 0000000000..1d33404405 --- /dev/null +++ b/tests/test-totalordermagl.c @@ -0,0 +1,33 @@ +/* Test totalordermagl. + Copyright 2023-2024 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include "signature.h" +SIGNATURE_CHECK (totalordermagl, int, (const long double *, const long double *)); + +#define TOTALORDER totalordermagl +#define TOTALORDER_TYPE memory_long_double +#define TOTALORDER_INF Infinityl +#define TOTALORDER_MINUS_ZERO minus_zerol +#define TOTALORDER_SETPAYLOAD setpayloadl +#define TOTALORDER_HAVE_SNAN HAVE_SNANL +#define TOTALORDER_POSITIVE_SNAN memory_positive_SNaNl +#define TOTALORDER_NEGATIVE_SNAN memory_negative_SNaNl +#include "test-totalordermag.h" -- 2.34.1 --nextPart16083472.XhxsbSUPYR--