Home | History | Annotate | Download | only in m4
      1 # ldexpl.m4 serial 16
      2 dnl Copyright (C) 2007-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_LDEXPL],
      8 [
      9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
     10   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
     11   AC_REQUIRE([gl_FUNC_ISNANL]) dnl for ISNANL_LIBM
     12 
     13   dnl Persuade glibc <math.h> to declare ldexpl().
     14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
     15 
     16   dnl Check whether it's declared.
     17   dnl Mac OS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
     18   AC_CHECK_DECL([ldexpl], , [HAVE_DECL_LDEXPL=0], [[#include <math.h>]])
     19 
     20   LDEXPL_LIBM=
     21   if test $HAVE_DECL_LDEXPL = 1; then
     22     gl_CHECK_LDEXPL_NO_LIBM
     23     if test $gl_cv_func_ldexpl_no_libm = no; then
     24       AC_CACHE_CHECK([whether ldexpl() can be used with libm],
     25         [gl_cv_func_ldexpl_in_libm],
     26         [
     27           save_LIBS="$LIBS"
     28           LIBS="$LIBS -lm"
     29           AC_LINK_IFELSE(
     30             [AC_LANG_PROGRAM(
     31                [[#include <math.h>
     32                  long double x;]],
     33                [[return ldexpl (x, -1) > 0;]])],
     34             [gl_cv_func_ldexpl_in_libm=yes],
     35             [gl_cv_func_ldexpl_in_libm=no])
     36           LIBS="$save_LIBS"
     37         ])
     38       if test $gl_cv_func_ldexpl_in_libm = yes; then
     39         LDEXPL_LIBM=-lm
     40       fi
     41     fi
     42     if test $gl_cv_func_ldexpl_no_libm = yes \
     43        || test $gl_cv_func_ldexpl_in_libm = yes; then
     44       save_LIBS="$LIBS"
     45       LIBS="$LIBS $LDEXPL_LIBM"
     46       gl_FUNC_LDEXPL_WORKS
     47       LIBS="$save_LIBS"
     48       case "$gl_cv_func_ldexpl_works" in
     49         *yes) gl_func_ldexpl=yes ;;
     50         *)    gl_func_ldexpl=no; REPLACE_LDEXPL=1 ;;
     51       esac
     52     else
     53       gl_func_ldexpl=no
     54     fi
     55     if test $gl_func_ldexpl = yes; then
     56       AC_DEFINE([HAVE_LDEXPL], [1],
     57         [Define if the ldexpl() function is available.])
     58     fi
     59   fi
     60   if test $HAVE_DECL_LDEXPL = 0 || test $gl_func_ldexpl = no; then
     61     dnl Find libraries needed to link lib/ldexpl.c.
     62     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
     63       AC_REQUIRE([gl_FUNC_LDEXP])
     64       LDEXPL_LIBM="$LDEXP_LIBM"
     65     else
     66       LDEXPL_LIBM="$ISNANL_LIBM"
     67     fi
     68   fi
     69   AC_SUBST([LDEXPL_LIBM])
     70 ])
     71 
     72 dnl Test whether ldexpl() can be used without linking with libm.
     73 dnl Set gl_cv_func_ldexpl_no_libm to 'yes' or 'no' accordingly.
     74 AC_DEFUN([gl_CHECK_LDEXPL_NO_LIBM],
     75 [
     76   AC_CACHE_CHECK([whether ldexpl() can be used without linking with libm],
     77     [gl_cv_func_ldexpl_no_libm],
     78     [
     79       AC_LINK_IFELSE(
     80         [AC_LANG_PROGRAM(
     81            [[#include <math.h>
     82              long double x;]],
     83            [[return ldexpl (x, -1) > 0;]])],
     84         [gl_cv_func_ldexpl_no_libm=yes],
     85         [gl_cv_func_ldexpl_no_libm=no])
     86     ])
     87 ])
     88 
     89 dnl Test whether ldexpl() works on finite numbers (this fails on AIX 5.1
     90 dnl and Mac OS X 10.4/PowerPC).
     91 AC_DEFUN([gl_FUNC_LDEXPL_WORKS],
     92 [
     93   AC_REQUIRE([AC_PROG_CC])
     94   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
     95   AC_CACHE_CHECK([whether ldexpl works], [gl_cv_func_ldexpl_works],
     96     [
     97       AC_RUN_IFELSE(
     98         [AC_LANG_SOURCE([[
     99 #include <math.h>
    100 extern
    101 #ifdef __cplusplus
    102 "C"
    103 #endif
    104 long double ldexpl (long double, int);
    105 int main()
    106 {
    107   int result = 0;
    108   {
    109     volatile long double x = 1.0;
    110     volatile long double y = ldexpl (x, -1);
    111     if (y != 0.5L)
    112       result |= 1;
    113   }
    114   {
    115     volatile long double x = 1.73205L;
    116     volatile long double y = ldexpl (x, 0);
    117     if (y != x)
    118       result |= 2;
    119   }
    120   return result;
    121 }]])],
    122         [gl_cv_func_ldexpl_works=yes],
    123         [gl_cv_func_ldexpl_works=no],
    124         [
    125 changequote(,)dnl
    126          case "$host_os" in
    127            aix | aix[3-6]*) gl_cv_func_ldexpl_works="guessing no";;
    128            *)               gl_cv_func_ldexpl_works="guessing yes";;
    129          esac
    130 changequote([,])dnl
    131         ])
    132     ])
    133 ])
    134