log1pl-ieee: Work around test failure on IRIX 6.5.
[gnulib.git] / m4 / log1pl.m4
1 # log1pl.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_LOG1PL],
8 [
9   m4_divert_text([DEFAULTS], [gl_log1pl_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_LOG1P])
13
14   dnl Persuade glibc <math.h> to declare log1pl().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16
17   dnl Test whether log1pl() exists. Assume that log1pl(), if it exists, is
18   dnl defined in the same library as log1p().
19   save_LIBS="$LIBS"
20   LIBS="$LIBS $LOG1P_LIBM"
21   AC_CHECK_FUNCS([log1pl])
22   LIBS="$save_LIBS"
23   if test $ac_cv_func_log1pl = yes; then
24     LOG1PL_LIBM="$LOG1P_LIBM"
25     m4_ifdef([gl_FUNC_LOG1PL_IEEE], [
26       if test $gl_log1pl_required = ieee && test $REPLACE_LOG1PL = 0; then
27         AC_CACHE_CHECK([whether log1pl works according to ISO C 99 with IEC 60559],
28           [gl_cv_func_log1pl_ieee],
29           [
30             save_LIBS="$LIBS"
31             LIBS="$LIBS $LOG1PL_LIBM"
32             AC_RUN_IFELSE(
33               [AC_LANG_SOURCE([[
34 #ifndef __NO_MATH_INLINES
35 # define __NO_MATH_INLINES 1 /* for glibc */
36 #endif
37 #include <math.h>
38 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
39 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
40 static long double dummy (long double x) { return 0; }
41 int main (int argc, char *argv[])
42 {
43   long double (*my_log1pl) (long double) = argc ? log1pl : dummy;
44   /* This test fails on AIX 7.1, IRIX 6.5.  */
45   long double y = my_log1pl (minus_zerol);
46   if (!(y == 0.0L) || (signbitl (minus_zerol) && !signbitl (y)))
47     return 1;
48   return 0;
49 }
50               ]])],
51               [gl_cv_func_log1pl_ieee=yes],
52               [gl_cv_func_log1pl_ieee=no],
53               [gl_cv_func_log1pl_ieee="guessing no"])
54             LIBS="$save_LIBS"
55           ])
56         case "$gl_cv_func_log1pl_ieee" in
57           *yes) ;;
58           *) REPLACE_LOG1PL=1 ;;
59         esac
60       fi
61     ])
62   else
63     HAVE_LOG1PL=0
64     dnl Find libraries needed to link lib/log1pl.c.
65     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
66       LOG1PL_LIBM="$LOG1P_LIBM"
67     else
68       AC_REQUIRE([gl_FUNC_ISNANL])
69       AC_REQUIRE([gl_FUNC_LOGL])
70       AC_REQUIRE([gl_FUNC_ROUNDL])
71       LOG1PL_LIBM=
72       dnl Append $ISNANL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
73       case " $LOG1PL_LIBM " in
74         *" $ISNANL_LIBM "*) ;;
75         *) LOG1PL_LIBM="$LOG1PL_LIBM $ISNANL_LIBM" ;;
76       esac
77       dnl Append $LOGL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
78       case " $LOG1PL_LIBM " in
79         *" $LOGL_LIBM "*) ;;
80         *) LOG1PL_LIBM="$LOG1PL_LIBM $LOGL_LIBM" ;;
81       esac
82       dnl Append $ROUNDL_LIBM to LOG1PL_LIBM, avoiding gratuitous duplicates.
83       case " $LOG1PL_LIBM " in
84         *" $ROUNDL_LIBM "*) ;;
85         *) LOG1PL_LIBM="$LOG1PL_LIBM $ROUNDL_LIBM" ;;
86       esac
87     fi
88   fi
89   AC_SUBST([LOG1PL_LIBM])
90 ])