immutable: Add tests.
[gnulib.git] / m4 / expm1f.m4
blobc18ff1a5025d2804ed8ffb3d4593ce3c7c7e0ed9
1 # expm1f.m4 serial 4
2 dnl Copyright (C) 2011-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_EXPM1F],
9   m4_divert_text([DEFAULTS], [gl_expm1f_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_EXPM1])
13   dnl Persuade glibc <math.h> to declare expm1f().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16   dnl Test whether expm1f() exists. Assume that expm1f(), if it exists, is
17   dnl defined in the same library as expm1().
18   save_LIBS="$LIBS"
19   LIBS="$LIBS $EXPM1_LIBM"
20   AC_CHECK_FUNCS([expm1f])
21   LIBS="$save_LIBS"
22   if test $ac_cv_func_expm1f = yes; then
23     EXPM1F_LIBM="$EXPM1_LIBM"
25     save_LIBS="$LIBS"
26     LIBS="$LIBS $EXPM1F_LIBM"
27     gl_FUNC_EXPM1F_WORKS
28     LIBS="$save_LIBS"
29     case "$gl_cv_func_expm1f_works" in
30       *yes) ;;
31       *) REPLACE_EXPM1F=1 ;;
32     esac
34     m4_ifdef([gl_FUNC_EXPM1F_IEEE], [
35       if test $gl_expm1f_required = ieee && test $REPLACE_EXPM1F = 0; then
36         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
37         AC_CACHE_CHECK([whether expm1f works according to ISO C 99 with IEC 60559],
38           [gl_cv_func_expm1f_ieee],
39           [
40             save_LIBS="$LIBS"
41             LIBS="$LIBS $EXPM1F_LIBM"
42             AC_RUN_IFELSE(
43               [AC_LANG_SOURCE([[
44 #ifndef __NO_MATH_INLINES
45 # define __NO_MATH_INLINES 1 /* for glibc */
46 #endif
47 #include <math.h>
48 ]gl_FLOAT_MINUS_ZERO_CODE[
49 ]gl_FLOAT_SIGNBIT_CODE[
50 #ifndef expm1f
51 extern
52 #ifdef __cplusplus
53 "C"
54 #endif
55 float expm1f (float);
56 #endif
57 /* Compare two numbers with ==.
58    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
59    'x == x' test.  */
60 static int
61 numeric_equal (float x, float y)
63   return x == y;
65 static float dummy (float x) { return 0; }
66 int main (int argc, char *argv[])
68   float (* volatile my_expm1f) (float) = argc ? expm1f : dummy;
69   /* Test expm1f(-0.0f).
70      This test fails on AIX 7.2.  */
71   float y = my_expm1f (minus_zerof);
72   if (signbitf (minus_zerof) && !signbitf (y))
73     return 1;
74   return 0;
76               ]])],
77               [gl_cv_func_expm1f_ieee=yes],
78               [gl_cv_func_expm1f_ieee=no],
79               [case "$host_os" in
80                                 # Guess yes on glibc systems.
81                  *-gnu* | gnu*) gl_cv_func_expm1f_ieee="guessing yes" ;;
82                                 # Guess yes on musl systems.
83                  *-musl*)       gl_cv_func_expm1f_ieee="guessing yes" ;;
84                                 # Guess yes on native Windows.
85                  mingw*)        gl_cv_func_expm1f_ieee="guessing yes" ;;
86                                 # Guess no on AIX.
87                  aix*)          gl_cv_func_expm1f_ieee="guessing no" ;;
88                                 # If we don't know, obey --enable-cross-guesses.
89                  *)             gl_cv_func_expm1f_ieee="$gl_cross_guess_normal" ;;
90                esac
91               ])
92             LIBS="$save_LIBS"
93           ])
94         case "$gl_cv_func_expm1f_ieee" in
95           *yes) ;;
96           *) REPLACE_EXPM1F=1 ;;
97         esac
98       fi
99     ])
100   else
101     HAVE_EXPM1F=0
102   fi
103   if test $HAVE_EXPM1F = 0 || test $REPLACE_EXPM1F = 1; then
104     dnl Find libraries needed to link lib/expm1f.c.
105     EXPM1F_LIBM="$EXPM1_LIBM"
106   fi
107   AC_SUBST([EXPM1F_LIBM])
110 dnl Test whether expm1f() works.
111 dnl On IRIX 6.5, for arguments <= -17.32868, it returns -5.6295e14.
112 AC_DEFUN([gl_FUNC_EXPM1F_WORKS],
114   AC_REQUIRE([AC_PROG_CC])
115   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
116   AC_CACHE_CHECK([whether expm1f works], [gl_cv_func_expm1f_works],
117     [
118       AC_RUN_IFELSE(
119         [AC_LANG_SOURCE([[
120 #include <math.h>
121 volatile float x;
122 float y;
123 int main ()
125   x = -100.0f;
126   y = expm1f (x);
127   if (y < -1.0f)
128     return 1;
129   return 0;
131 ]])],
132         [gl_cv_func_expm1f_works=yes],
133         [gl_cv_func_expm1f_works=no],
134         [case "$host_os" in
135            irix*)  gl_cv_func_expm1f_works="guessing no" ;;
136                    # Guess yes on native Windows.
137            mingw*) gl_cv_func_expm1f_works="guessing yes" ;;
138            *)      gl_cv_func_expm1f_works="guessing yes" ;;
139          esac
140         ])
141     ])