Merge commit 'a39d4083cab589d7cd6a13e8a4b8db8875261d75'
[gnulib.git] / m4 / ilogbl.m4
1 # ilogbl.m4 serial 1
2 dnl Copyright (C) 2010-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_ILOGBL],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
11   AC_REQUIRE([gl_FUNC_ILOGB])
12
13   dnl Persuade glibc <math.h> to declare ilogbl().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15
16   dnl Test whether ilogbl() exists. Assume that ilogbl(), if it exists, is
17   dnl defined in the same library as ilogb().
18   save_LIBS="$LIBS"
19   LIBS="$LIBS $ILOGB_LIBM"
20   AC_CACHE_CHECK([for ilogbl],
21     [gl_cv_func_ilogbl],
22     [
23       AC_LINK_IFELSE(
24         [AC_LANG_PROGRAM(
25            [[#ifndef __NO_MATH_INLINES
26              # define __NO_MATH_INLINES 1 /* for glibc */
27              #endif
28              #include <math.h>
29              int (*funcptr) (long double) = ilogbl;
30              long double x;]],
31            [[return (funcptr (x) % 2) == 0
32                     || (ilogbl (x) % 2) == 0;]])],
33         [gl_cv_func_ilogbl=yes],
34         [gl_cv_func_ilogbl=no])
35     ])
36   LIBS="$save_LIBS"
37   if test $gl_cv_func_ilogbl = yes; then
38     ILOGBL_LIBM="$ILOGB_LIBM"
39   else
40     HAVE_ILOGBL=0
41     dnl Find libraries needed to link lib/ilogbl.c.
42     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
43       ILOGBL_LIBM="$ILOGB_LIBM"
44     else
45       AC_REQUIRE([gl_FUNC_FREXPL])
46       AC_REQUIRE([gl_FUNC_ISNANL])
47       ILOGBL_LIBM=
48       dnl Append $FREXPL_LIBM to ILOGBL_LIBM, avoiding gratuitous duplicates.
49       case " $ILOGBL_LIBM " in
50         *" $FREXPL_LIBM "*) ;;
51         *) ILOGBL_LIBM="$ILOGBL_LIBM $FREXPL_LIBM" ;;
52       esac
53       dnl Append $ISNANL_LIBM to ILOGBL_LIBM, avoiding gratuitous duplicates.
54       case " $ILOGBL_LIBM " in
55         *" $ISNANL_LIBM "*) ;;
56         *) ILOGBL_LIBM="$ILOGBL_LIBM $ISNANL_LIBM" ;;
57       esac
58     fi
59   fi
60   AC_SUBST([ILOGBL_LIBM])
61 ])