Merge branch 'stable'
[gnulib.git] / m4 / log1pf.m4
1 # log1pf.m4 serial 2
2 dnl Copyright (C) 2012 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.
6
7 AC_DEFUN([gl_FUNC_LOG1PF],
8 [
9   m4_divert_text([DEFAULTS], [gl_log1pf_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_FUNC_LOG1P])
12
13   dnl Persuade glibc <math.h> to declare log1pf().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16   dnl Test whether log1pf() exists. Assume that log1pf(), if it exists, is
17   dnl defined in the same library as log1p().
18   save_LIBS="$LIBS"
19   LIBS="$LIBS $LOG1P_LIBM"
20   AC_CHECK_FUNCS([log1pf])
21   LIBS="$save_LIBS"
22   if test $ac_cv_func_log1pf = yes; then
23     LOG1PF_LIBM="$LOG1P_LIBM"
24
25     save_LIBS="$LIBS"
26     LIBS="$LIBS $LOG1PF_LIBM"
27     gl_FUNC_LOG1PF_WORKS
28     LIBS="$save_LIBS"
29     case "$gl_cv_func_log1pf_works" in
30       *yes) ;;
31       *) REPLACE_LOG1PF=1 ;;
32     esac
33
34     m4_ifdef([gl_FUNC_LOG1PF_IEEE], [
35       if test $gl_log1pf_required = ieee && test $REPLACE_LOG1PF = 0; then
36         AC_CACHE_CHECK([whether log1pf works according to ISO C 99 with IEC 60559],
37           [gl_cv_func_log1pf_ieee],
38           [
39             save_LIBS="$LIBS"
40             LIBS="$LIBS $LOG1PF_LIBM"
41             AC_RUN_IFELSE(
42               [AC_LANG_SOURCE([[
43 #ifndef __NO_MATH_INLINES
44 # define __NO_MATH_INLINES 1 /* for glibc */
45 #endif
46 #include <math.h>
47 ]gl_FLOAT_MINUS_ZERO_CODE[
48 ]gl_FLOAT_SIGNBIT_CODE[
49 static float dummy (float x) { return 0; }
50 int main (int argc, char *argv[])
51 {
52   float (*my_log1pf) (float) = argc ? log1pf : dummy;
53   /* This test fails on OpenBSD 4.9, AIX 7.1.  */
54   float y = my_log1pf (minus_zerof);
55   if (!(y == 0.0f) || (signbitf (minus_zerof) && !signbitf (y)))
56     return 1;
57   return 0;
58 }
59               ]])],
60               [gl_cv_func_log1pf_ieee=yes],
61               [gl_cv_func_log1pf_ieee=no],
62               [gl_cv_func_log1pf_ieee="guessing no"])
63             LIBS="$save_LIBS"
64           ])
65         case "$gl_cv_func_log1pf_ieee" in
66           *yes) ;;
67           *) REPLACE_LOG1PF=1 ;;
68         esac
69       fi
70     ])
71   else
72     HAVE_LOG1PF=0
73   fi
74   if test $HAVE_LOG1PF = 0 || test $REPLACE_LOG1PF = 1; then
75     dnl Find libraries needed to link lib/log1pf.c.
76     LOG1PF_LIBM="$LOG1P_LIBM"
77   fi
78   AC_SUBST([LOG1PF_LIBM])
79 ])
80
81 dnl Test whether log1pf() works.
82 dnl On IRIX 6.5, log1pf(-1.0f) returns +Infinity instead of -Infinity.
83 AC_DEFUN([gl_FUNC_LOG1PF_WORKS],
84 [
85   AC_REQUIRE([AC_PROG_CC])
86   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
87   AC_CACHE_CHECK([whether log1pf works], [gl_cv_func_log1pf_works],
88     [
89       AC_RUN_IFELSE(
90         [AC_LANG_SOURCE([[
91 #include <math.h>
92 volatile float x;
93 float y;
94 int main ()
95 {
96   x = -1.0f;
97   y = log1pf (x);
98   if (!(y + y == y && y < 0.0f))
99     return 1;
100   return 0;
101 }
102 ]])],
103         [gl_cv_func_log1pf_works=yes],
104         [gl_cv_func_log1pf_works=no],
105         [case "$host_os" in
106            irix*) gl_cv_func_log1pf_works="guessing no";;
107            *)     gl_cv_func_log1pf_works="guessing yes";;
108          esac
109         ])
110     ])
111 ])