Blame m4/ldexpl.m4

Packit Service a2489d
# ldexpl.m4 serial 17
Packit Service a2489d
dnl Copyright (C) 2007-2018 Free Software Foundation, Inc.
Packit Service a2489d
dnl This file is free software; the Free Software Foundation
Packit Service a2489d
dnl gives unlimited permission to copy and/or distribute it,
Packit Service a2489d
dnl with or without modifications, as long as this notice is preserved.
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_FUNC_LDEXPL],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([gl_MATH_H_DEFAULTS])
Packit Service a2489d
  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
Packit Service a2489d
  AC_REQUIRE([gl_FUNC_ISNANL]) dnl for ISNANL_LIBM
Packit Service a2489d
Packit Service a2489d
  dnl Persuade glibc <math.h> to declare ldexpl().
Packit Service a2489d
  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
Packit Service a2489d
Packit Service a2489d
  dnl Check whether it's declared.
Packit Service a2489d
  dnl Mac OS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
Packit Service a2489d
  AC_CHECK_DECL([ldexpl], , [HAVE_DECL_LDEXPL=0], [[#include <math.h>]])
Packit Service a2489d
Packit Service a2489d
  LDEXPL_LIBM=
Packit Service a2489d
  if test $HAVE_DECL_LDEXPL = 1; then
Packit Service a2489d
    gl_CHECK_LDEXPL_NO_LIBM
Packit Service a2489d
    if test $gl_cv_func_ldexpl_no_libm = no; then
Packit Service a2489d
      AC_CACHE_CHECK([whether ldexpl() can be used with libm],
Packit Service a2489d
        [gl_cv_func_ldexpl_in_libm],
Packit Service a2489d
        [
Packit Service a2489d
          save_LIBS="$LIBS"
Packit Service a2489d
          LIBS="$LIBS -lm"
Packit Service a2489d
          AC_LINK_IFELSE(
Packit Service a2489d
            [AC_LANG_PROGRAM(
Packit Service a2489d
               [[#include <math.h>
Packit Service a2489d
                 long double x;]],
Packit Service a2489d
               [[return ldexpl (x, -1) > 0;]])],
Packit Service a2489d
            [gl_cv_func_ldexpl_in_libm=yes],
Packit Service a2489d
            [gl_cv_func_ldexpl_in_libm=no])
Packit Service a2489d
          LIBS="$save_LIBS"
Packit Service a2489d
        ])
Packit Service a2489d
      if test $gl_cv_func_ldexpl_in_libm = yes; then
Packit Service a2489d
        LDEXPL_LIBM=-lm
Packit Service a2489d
      fi
Packit Service a2489d
    fi
Packit Service a2489d
    if test $gl_cv_func_ldexpl_no_libm = yes \
Packit Service a2489d
       || test $gl_cv_func_ldexpl_in_libm = yes; then
Packit Service a2489d
      save_LIBS="$LIBS"
Packit Service a2489d
      LIBS="$LIBS $LDEXPL_LIBM"
Packit Service a2489d
      gl_FUNC_LDEXPL_WORKS
Packit Service a2489d
      LIBS="$save_LIBS"
Packit Service a2489d
      case "$gl_cv_func_ldexpl_works" in
Packit Service a2489d
        *yes) gl_func_ldexpl=yes ;;
Packit Service a2489d
        *)    gl_func_ldexpl=no; REPLACE_LDEXPL=1 ;;
Packit Service a2489d
      esac
Packit Service a2489d
    else
Packit Service a2489d
      gl_func_ldexpl=no
Packit Service a2489d
    fi
Packit Service a2489d
    if test $gl_func_ldexpl = yes; then
Packit Service a2489d
      AC_DEFINE([HAVE_LDEXPL], [1],
Packit Service a2489d
        [Define if the ldexpl() function is available.])
Packit Service a2489d
    fi
Packit Service a2489d
  fi
Packit Service a2489d
  if test $HAVE_DECL_LDEXPL = 0 || test $gl_func_ldexpl = no; then
Packit Service a2489d
    dnl Find libraries needed to link lib/ldexpl.c.
Packit Service a2489d
    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
Packit Service a2489d
      AC_REQUIRE([gl_FUNC_LDEXP])
Packit Service a2489d
      LDEXPL_LIBM="$LDEXP_LIBM"
Packit Service a2489d
    else
Packit Service a2489d
      LDEXPL_LIBM="$ISNANL_LIBM"
Packit Service a2489d
    fi
Packit Service a2489d
  fi
Packit Service a2489d
  AC_SUBST([LDEXPL_LIBM])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether ldexpl() can be used without linking with libm.
Packit Service a2489d
dnl Set gl_cv_func_ldexpl_no_libm to 'yes' or 'no' accordingly.
Packit Service a2489d
AC_DEFUN([gl_CHECK_LDEXPL_NO_LIBM],
Packit Service a2489d
[
Packit Service a2489d
  AC_CACHE_CHECK([whether ldexpl() can be used without linking with libm],
Packit Service a2489d
    [gl_cv_func_ldexpl_no_libm],
Packit Service a2489d
    [
Packit Service a2489d
      AC_LINK_IFELSE(
Packit Service a2489d
        [AC_LANG_PROGRAM(
Packit Service a2489d
           [[#include <math.h>
Packit Service a2489d
             long double x;]],
Packit Service a2489d
           [[return ldexpl (x, -1) > 0;]])],
Packit Service a2489d
        [gl_cv_func_ldexpl_no_libm=yes],
Packit Service a2489d
        [gl_cv_func_ldexpl_no_libm=no])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether ldexpl() works on finite numbers (this fails on AIX 5.1
Packit Service a2489d
dnl and Mac OS X 10.4/PowerPC).
Packit Service a2489d
AC_DEFUN([gl_FUNC_LDEXPL_WORKS],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether ldexpl works], [gl_cv_func_ldexpl_works],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <math.h>
Packit Service a2489d
extern
Packit Service a2489d
#ifdef __cplusplus
Packit Service a2489d
"C"
Packit Service a2489d
#endif
Packit Service a2489d
long double ldexpl (long double, int);
Packit Service a2489d
int main()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
  {
Packit Service a2489d
    volatile long double x = 1.0;
Packit Service a2489d
    volatile long double y = ldexpl (x, -1);
Packit Service a2489d
    if (y != 0.5L)
Packit Service a2489d
      result |= 1;
Packit Service a2489d
  }
Packit Service a2489d
  {
Packit Service a2489d
    volatile long double x = 1.73205L;
Packit Service a2489d
    volatile long double y = ldexpl (x, 0);
Packit Service a2489d
    if (y != x)
Packit Service a2489d
      result |= 2;
Packit Service a2489d
  }
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_ldexpl_works=yes],
Packit Service a2489d
        [gl_cv_func_ldexpl_works=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
           aix | aix[3-6]*) gl_cv_func_ldexpl_works="guessing no" ;;
Packit Service a2489d
                            # Guess yes on native Windows.
Packit Service a2489d
           mingw*)          gl_cv_func_ldexpl_works="guessing yes" ;;
Packit Service a2489d
           *)               gl_cv_func_ldexpl_works="guessing yes" ;;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])