]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
sinl: Work around NetBSD 10.0 bug.
authorBruno Haible <bruno@clisp.org>
Thu, 4 Dec 2025 21:51:59 +0000 (22:51 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 4 Dec 2025 21:51:59 +0000 (22:51 +0100)
* lib/math.in.h (sinl): Consider REPLACE_SINL.
* m4/sinl.m4 (gl_FUNC_SINL): Test whether sinl works. Set REPLACE_SINL
to 1 if not.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_SINL.
* modules/math-h (Makefile.am): Substitute REPLACE_SINL.
* modules/sinl (configure.ac): Consider REPLACE_SINL.
* doc/posix-functions/sinl.texi: Mention the NetBSD bug.

ChangeLog
doc/posix-functions/sinl.texi
lib/math.in.h
m4/math_h.m4
m4/sinl.m4
modules/math-h
modules/sinl

index cafe5e73c437bfd88324b6aacfaad947d1698c2e..9e65fefdf97e75ceba1051362c71564cba15b55c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2025-12-04  Bruno Haible  <bruno@clisp.org>
+
+       sinl: Work around NetBSD 10.0 bug.
+       * lib/math.in.h (sinl): Consider REPLACE_SINL.
+       * m4/sinl.m4 (gl_FUNC_SINL): Test whether sinl works. Set REPLACE_SINL
+       to 1 if not.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_SINL.
+       * modules/math-h (Makefile.am): Substitute REPLACE_SINL.
+       * modules/sinl (configure.ac): Consider REPLACE_SINL.
+       * doc/posix-functions/sinl.texi: Mention the NetBSD bug.
+
 2025-12-04  Bruno Haible  <bruno@clisp.org>
 
        expf, sinf, cosf, ...: Fix possible error on MSVC.
index b6545296cef4819e39e0fb1fabf80a83c2fb4d76..82b0158985f7f51bae38095277f20e1320df892b 100644 (file)
@@ -15,6 +15,11 @@ FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, Solaris 9, Cygwin 1
 @item
 This function is only defined as a macro with arguments on some platforms:
 MSVC 14.
+@item
+This function returns a value that is larger that the argument,
+for some positive arguments,
+on some platforms:
+NetBSD 10.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index e456f023339dd805e0b9b2a91ec57c83cf6f5242..53450d4c60d426c6c78cbba1fa72c3a37f542ee9 100644 (file)
@@ -2175,11 +2175,20 @@ _GL_WARN_ON_USE (sinf, "sinf is unportable - "
 #endif
 
 #if @GNULIB_SINL@
-# if !@HAVE_SINL@ || !@HAVE_DECL_SINL@
-#  undef sinl
+# if @REPLACE_SINL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef sinl
+#   define sinl rpl_sinl
+#  endif
+_GL_FUNCDECL_RPL (sinl, long double, (long double x), );
+_GL_CXXALIAS_RPL (sinl, long double, (long double x));
+# else
+#  if !@HAVE_SINL@ || !@HAVE_DECL_SINL@
+#   undef sinl
 _GL_FUNCDECL_SYS (sinl, long double, (long double x), );
-# endif
+#  endif
 _GL_CXXALIAS_SYS (sinl, long double, (long double x));
+# endif
 # if __GLIBC__ >= 2
 _GL_CXXALIASWARN (sinl);
 # endif
index fa2ace3fe42b94b441949b9084bacf405568cb75..805cca471db0dc84983dc0be2ba19d5515c8cb24 100644 (file)
@@ -1,5 +1,5 @@
 # math_h.m4
-# serial 141
+# serial 142
 dnl Copyright (C) 2007-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -396,6 +396,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_SIGNBIT_USING_BUILTINS=0; AC_SUBST([REPLACE_SIGNBIT_USING_BUILTINS])
   REPLACE_SINF=0;                   AC_SUBST([REPLACE_SINF])
   REPLACE_SINHF=0;                  AC_SUBST([REPLACE_SINHF])
+  REPLACE_SINL=0;                   AC_SUBST([REPLACE_SINL])
   REPLACE_SQRTF=0;                  AC_SUBST([REPLACE_SQRTF])
   REPLACE_SQRTL=0;                  AC_SUBST([REPLACE_SQRTL])
   REPLACE_TANF=0;                   AC_SUBST([REPLACE_TANF])
index 802528a355a555248fa93e21ec7e6378a90cbd15..9d9fcfb4519e7da8147e20bdc38f1993e7ef0df3 100644 (file)
@@ -1,5 +1,5 @@
 # sinl.m4
-# serial 10
+# serial 11
 dnl Copyright (C) 2010-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -60,9 +60,65 @@ AC_DEFUN([gl_FUNC_SINL],
     dnl Also check whether it's declared.
     dnl Mac OS X 10.3 has sinl() in libc but doesn't declare it in <math.h>.
     AC_CHECK_DECL([sinl], , [HAVE_DECL_SINL=0], [[#include <math.h>]])
+    if test $REPLACE_SINL = 0; then
+      AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+      AC_CACHE_CHECK([whether sinl works],
+        [gl_cv_func_sinl_works],
+        [
+          saved_LIBS="$LIBS"
+          LIBS="$LIBS $SINL_LIBM"
+          AC_RUN_IFELSE(
+            [AC_LANG_SOURCE([[
+#ifndef __NO_MATH_INLINES
+# define __NO_MATH_INLINES 1 /* for glibc */
+#endif
+#include <math.h>
+#undef sinl
+extern
+#ifdef __cplusplus
+"C"
+#endif
+long double sinl (long double);
+static long double dummy (long double x) { return 0; }
+int main (int argc, char *argv[])
+{
+  long double (* volatile my_sinl) (long double) = argc ? sinl : dummy;
+  int result = 0;
+  /* On NetBSD 10.0 the system's native sinl() is buggy:
+     it does not obey the inequality |sin(x)| <= |x|.  */
+  {
+    volatile long double x = 0.000000000000000004L;
+    if (my_sinl (x) > x)
+      result |= 1;
+  }
+  return result;
+}
+            ]])],
+            [gl_cv_func_sinl_works=yes],
+            [gl_cv_func_sinl_works=no],
+            [case "$host_os" in
+                                   # Guess yes on glibc systems.
+               *-gnu* | gnu*)      gl_cv_func_sinl_works="guessing yes" ;;
+                                   # Guess yes on musl systems.
+               *-musl* | midipix*) gl_cv_func_sinl_works="guessing yes" ;;
+                                   # Guess yes on native Windows.
+               mingw* | windows*)  gl_cv_func_sinl_works="guessing yes" ;;
+                                   # If we don't know, obey --enable-cross-guesses.
+               *)                  gl_cv_func_sinl_works="$gl_cross_guess_normal" ;;
+             esac
+            ])
+          LIBS="$saved_LIBS"
+        ])
+      case "$gl_cv_func_sinl_works" in
+        *yes) ;;
+        *) REPLACE_SINL=1 ;;
+      esac
+    fi
   else
     HAVE_DECL_SINL=0
     HAVE_SINL=0
+  fi
+  if test $HAVE_SINL = 0 || test $REPLACE_SINL = 1; then
     dnl Find libraries needed to link lib/sinl.c, lib/sincosl.c, lib/trigl.c.
     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
       AC_REQUIRE([gl_FUNC_SIN])
index 5d0697f4b19fb79f01aa60284e0af7b254a97fe0..da3214ad4eb2cda9a080d1f5ffc3f7524449480f 100644 (file)
@@ -352,6 +352,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_SIGNBIT_USING_BUILTINS''@|$(REPLACE_SIGNBIT_USING_BUILTINS)|g' \
              -e 's|@''REPLACE_SINF''@|$(REPLACE_SINF)|g' \
              -e 's|@''REPLACE_SINHF''@|$(REPLACE_SINHF)|g' \
+             -e 's|@''REPLACE_SINL''@|$(REPLACE_SINL)|g' \
              -e 's|@''REPLACE_SQRTF''@|$(REPLACE_SQRTF)|g' \
              -e 's|@''REPLACE_SQRTL''@|$(REPLACE_SQRTL)|g' \
              -e 's|@''REPLACE_TANF''@|$(REPLACE_TANF)|g' \
index f6a255067f01686ab8b292479dacfe5f7207ef65..bc63bf8d943157c1b489f6de656b0b6d37761482 100644 (file)
@@ -11,15 +11,16 @@ m4/sinl.m4
 Depends-on:
 math-h
 extensions
-sin             [test $HAVE_SINL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
-float-h         [test $HAVE_SINL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-isnanl          [test $HAVE_SINL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-floor           [test $HAVE_SINL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-floorl          [test $HAVE_SINL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+sin             [{ test $HAVE_SINL = 0 || test $REPLACE_SINL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+float-h         [{ test $HAVE_SINL = 0 || test $REPLACE_SINL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+isnanl          [{ test $HAVE_SINL = 0 || test $REPLACE_SINL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+floor           [{ test $HAVE_SINL = 0 || test $REPLACE_SINL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+floorl          [{ test $HAVE_SINL = 0 || test $REPLACE_SINL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 
 configure.ac:
 gl_FUNC_SINL
-gl_CONDITIONAL([GL_COND_OBJ_SINL], [test $HAVE_SINL = 0])
+gl_CONDITIONAL([GL_COND_OBJ_SINL],
+               [test $HAVE_SINL = 0 || test $REPLACE_SINL = 1])
 AM_COND_IF([GL_COND_OBJ_SINL], [
   if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0; then
     AC_LIBOBJ([sincosl])