reallocarray: Don't assume unportable behaviour of realloc.
[gnulib.git] / m4 / log1pf.m4
blob4b9581836b32945bb4d3b94f0cdd93fe18f2111b
1 # log1pf.m4
2 # serial 11
3 dnl Copyright (C) 2012-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
9 AC_DEFUN([gl_FUNC_LOG1PF],
11   m4_divert_text([DEFAULTS], [gl_log1pf_required=plain])
12   AC_REQUIRE([gl_MATH_H_DEFAULTS])
13   AC_REQUIRE([gl_FUNC_LOG1P])
15   dnl Persuade glibc <math.h> to declare log1pf().
16   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
18   dnl Test whether log1pf() exists. Assume that log1pf(), if it exists, is
19   dnl defined in the same library as log1p().
20   saved_LIBS="$LIBS"
21   LIBS="$LIBS $LOG1P_LIBM"
22   AC_CHECK_FUNCS([log1pf])
23   LIBS="$saved_LIBS"
24   if test $ac_cv_func_log1pf = yes; then
25     LOG1PF_LIBM="$LOG1P_LIBM"
27     saved_LIBS="$LIBS"
28     LIBS="$LIBS $LOG1PF_LIBM"
29     gl_FUNC_LOG1PF_WORKS
30     LIBS="$saved_LIBS"
31     case "$gl_cv_func_log1pf_works" in
32       *yes) ;;
33       *) REPLACE_LOG1PF=1 ;;
34     esac
36     m4_ifdef([gl_FUNC_LOG1PF_IEEE], [
37       if test $gl_log1pf_required = ieee && test $REPLACE_LOG1PF = 0; then
38         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
39         AC_CACHE_CHECK([whether log1pf works according to ISO C 99 with IEC 60559],
40           [gl_cv_func_log1pf_ieee],
41           [
42             saved_LIBS="$LIBS"
43             LIBS="$LIBS $LOG1PF_LIBM"
44             AC_RUN_IFELSE(
45               [AC_LANG_SOURCE([[
46 #ifndef __NO_MATH_INLINES
47 # define __NO_MATH_INLINES 1 /* for glibc */
48 #endif
49 #include <math.h>
50 ]gl_FLOAT_MINUS_ZERO_CODE[
51 ]gl_FLOAT_SIGNBIT_CODE[
52 static float dummy (float x) { return 0; }
53 int main (int argc, char *argv[])
55   float (* volatile my_log1pf) (float) = argc ? log1pf : dummy;
56   /* This test fails on OpenBSD 4.9, AIX 7.1.  */
57   float y = my_log1pf (minus_zerof);
58   if (!(y == 0.0f) || (signbitf (minus_zerof) && !signbitf (y)))
59     return 1;
60   return 0;
62               ]])],
63               [gl_cv_func_log1pf_ieee=yes],
64               [gl_cv_func_log1pf_ieee=no],
65               [case "$host_os" in
66                                      # Guess yes on glibc systems.
67                  *-gnu* | gnu*)      gl_cv_func_log1pf_ieee="guessing yes" ;;
68                                      # Guess yes on musl systems.
69                  *-musl* | midipix*) gl_cv_func_log1pf_ieee="guessing yes" ;;
70                                      # Guess yes on native Windows.
71                  mingw* | windows*)  gl_cv_func_log1pf_ieee="guessing yes" ;;
72                                      # If we don't know, obey --enable-cross-guesses.
73                  *)                  gl_cv_func_log1pf_ieee="$gl_cross_guess_normal" ;;
74                esac
75               ])
76             LIBS="$saved_LIBS"
77           ])
78         case "$gl_cv_func_log1pf_ieee" in
79           *yes) ;;
80           *) REPLACE_LOG1PF=1 ;;
81         esac
82       fi
83     ])
84   else
85     HAVE_LOG1PF=0
86   fi
87   if test $HAVE_LOG1PF = 0 || test $REPLACE_LOG1PF = 1; then
88     dnl Find libraries needed to link lib/log1pf.c.
89     LOG1PF_LIBM="$LOG1P_LIBM"
90   fi
91   AC_SUBST([LOG1PF_LIBM])
94 dnl Test whether log1pf() works.
95 dnl On IRIX 6.5, log1pf(-1.0f) returns +Infinity instead of -Infinity.
96 AC_DEFUN([gl_FUNC_LOG1PF_WORKS],
98   AC_REQUIRE([AC_PROG_CC])
99   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
100   AC_CACHE_CHECK([whether log1pf works], [gl_cv_func_log1pf_works],
101     [
102       AC_RUN_IFELSE(
103         [AC_LANG_SOURCE([[
104 #include <math.h>
105 volatile float x;
106 float y;
107 int main ()
109   x = -1.0f;
110   y = log1pf (x);
111   if (!(y + y == y && y < 0.0f))
112     return 1;
113   return 0;
115 ]])],
116         [gl_cv_func_log1pf_works=yes],
117         [gl_cv_func_log1pf_works=no],
118         [case "$host_os" in
119            irix*)             gl_cv_func_log1pf_works="guessing no" ;;
120                               # Guess yes on native Windows.
121            mingw* | windows*) gl_cv_func_log1pf_works="guessing yes" ;;
122            *)                 gl_cv_func_log1pf_works="guessing yes" ;;
123          esac
124         ])
125     ])