Merge commit 'a39d4083cab589d7cd6a13e8a4b8db8875261d75'
[gnulib.git] / m4 / log10l.m4
1 # log10l.m4 serial 3
2 dnl Copyright (C) 2011-2014 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_LOG10L],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
11   AC_REQUIRE([gl_FUNC_LOG10])
12
13   dnl Persuade glibc <math.h> to declare log10l().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16   dnl Test whether log10l() is declared. On AIX 5.1 it is not declared.
17   AC_CHECK_DECL([log10l], , [HAVE_DECL_LOG10L=0], [[#include <math.h>]])
18
19   dnl Test whether log10l() exists. Assume that log10l(), if it exists, is
20   dnl defined in the same library as log10().
21   save_LIBS="$LIBS"
22   LIBS="$LIBS $LOG10_LIBM"
23   AC_CHECK_FUNCS([log10l])
24   LIBS="$save_LIBS"
25   if test $ac_cv_func_log10l = yes; then
26     LOG10L_LIBM="$LOG10_LIBM"
27
28     save_LIBS="$LIBS"
29     LIBS="$LIBS $LOG10L_LIBM"
30     gl_FUNC_LOG10L_WORKS
31     LIBS="$save_LIBS"
32     case "$gl_cv_func_log10l_works" in
33       *yes) ;;
34       *) REPLACE_LOG10L=1 ;;
35     esac
36   else
37     HAVE_LOG10L=0
38   fi
39   if test $HAVE_LOG10L = 0 || test $REPLACE_LOG10L = 1; then
40     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
41       LOG10L_LIBM="$LOG10_LIBM"
42     else
43       if test $HAVE_LOG10L = 0; then
44         AC_REQUIRE([gl_FUNC_LOGL])
45         LOG10L_LIBM="$LOGL_LIBM"
46       fi
47     fi
48   fi
49   AC_SUBST([LOG10L_LIBM])
50 ])
51
52 dnl Test whether log10l() works.
53 dnl On OSF/1 5.1, log10l(-0.0L) is NaN.
54 dnl On IRIX 6.5, log10l(-0.0L) is an unnormalized negative infinity
55 dnl 0xFFF00000000000007FF0000000000000, should be
56 dnl 0xFFF00000000000000000000000000000.
57 dnl On AIX 5.1, log10l(-0.0L) is finite if it's not the first log10l call
58 dnl in the program.
59 AC_DEFUN([gl_FUNC_LOG10L_WORKS],
60 [
61   AC_REQUIRE([AC_PROG_CC])
62   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
63   AC_CACHE_CHECK([whether log10l works], [gl_cv_func_log10l_works],
64     [
65       AC_RUN_IFELSE(
66         [AC_LANG_SOURCE([[
67 #include <math.h>
68 #ifndef log10l /* for AIX */
69 extern
70 #ifdef __cplusplus
71 "C"
72 #endif
73 long double log10l (long double);
74 #endif
75 volatile long double x;
76 long double y;
77 int main ()
78 {
79   /* Dummy call, to trigger the AIX 5.1 bug.  */
80   x = 0.6L;
81   y = log10l (x);
82   /* This test fails on AIX 5.1, IRIX 6.5, OSF/1 5.1.  */
83   x = -0.0L;
84   y = log10l (x);
85   if (!(y + y == y))
86     return 1;
87   return 0;
88 }
89 ]])],
90         [gl_cv_func_log10l_works=yes],
91         [gl_cv_func_log10l_works=no],
92         [case "$host_os" in
93            aix* | irix* | osf*) gl_cv_func_log10l_works="guessing no";;
94            *)                   gl_cv_func_log10l_works="guessing yes";;
95          esac
96         ])
97     ])
98 ])