Blame m4/frexpl.m4

Packit Service a2489d
# frexpl.m4 serial 21
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_FREXPL],
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
Packit Service a2489d
  dnl Persuade glibc <math.h> to declare frexpl().
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 frexpl() in libc but doesn't declare it in <math.h>.
Packit Service a2489d
  AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
Packit Service a2489d
Packit Service a2489d
  FREXPL_LIBM=
Packit Service a2489d
  if test $HAVE_DECL_FREXPL = 1; then
Packit Service a2489d
    gl_CHECK_FREXPL_NO_LIBM
Packit Service a2489d
    if test $gl_cv_func_frexpl_no_libm = no; then
Packit Service a2489d
      AC_CACHE_CHECK([whether frexpl() can be used with libm],
Packit Service a2489d
        [gl_cv_func_frexpl_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
               [[int e; return frexpl (x, &e) > 0;]])],
Packit Service a2489d
            [gl_cv_func_frexpl_in_libm=yes],
Packit Service a2489d
            [gl_cv_func_frexpl_in_libm=no])
Packit Service a2489d
          LIBS="$save_LIBS"
Packit Service a2489d
        ])
Packit Service a2489d
      if test $gl_cv_func_frexpl_in_libm = yes; then
Packit Service a2489d
        FREXPL_LIBM=-lm
Packit Service a2489d
      fi
Packit Service a2489d
    fi
Packit Service a2489d
    if test $gl_cv_func_frexpl_no_libm = yes \
Packit Service a2489d
       || test $gl_cv_func_frexpl_in_libm = yes; then
Packit Service a2489d
      save_LIBS="$LIBS"
Packit Service a2489d
      LIBS="$LIBS $FREXPL_LIBM"
Packit Service a2489d
      gl_FUNC_FREXPL_WORKS
Packit Service a2489d
      LIBS="$save_LIBS"
Packit Service a2489d
      case "$gl_cv_func_frexpl_works" in
Packit Service a2489d
        *yes) gl_func_frexpl=yes ;;
Packit Service a2489d
        *)    gl_func_frexpl=no; REPLACE_FREXPL=1 ;;
Packit Service a2489d
      esac
Packit Service a2489d
    else
Packit Service a2489d
      gl_func_frexpl=no
Packit Service a2489d
    fi
Packit Service a2489d
    if test $gl_func_frexpl = yes; then
Packit Service a2489d
      AC_DEFINE([HAVE_FREXPL], [1],
Packit Service a2489d
        [Define if the frexpl() function is available.])
Packit Service a2489d
    fi
Packit Service a2489d
  fi
Packit Service a2489d
  if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then
Packit Service a2489d
    dnl Find libraries needed to link lib/frexpl.c.
Packit Service a2489d
    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
Packit Service a2489d
      AC_REQUIRE([gl_FUNC_FREXP])
Packit Service a2489d
      FREXPL_LIBM="$FREXP_LIBM"
Packit Service a2489d
    else
Packit Service a2489d
      FREXPL_LIBM=
Packit Service a2489d
    fi
Packit Service a2489d
  fi
Packit Service a2489d
  AC_SUBST([FREXPL_LIBM])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
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
  dnl Check whether it's declared.
Packit Service a2489d
  dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
Packit Service a2489d
  AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
Packit Service a2489d
  if test $HAVE_DECL_FREXPL = 1; then
Packit Service a2489d
    gl_CHECK_FREXPL_NO_LIBM
Packit Service a2489d
    if test $gl_cv_func_frexpl_no_libm = yes; then
Packit Service a2489d
      gl_FUNC_FREXPL_WORKS
Packit Service a2489d
      case "$gl_cv_func_frexpl_works" in
Packit Service a2489d
        *yes) gl_func_frexpl_no_libm=yes ;;
Packit Service a2489d
        *)    gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;;
Packit Service a2489d
      esac
Packit Service a2489d
    else
Packit Service a2489d
      gl_func_frexpl_no_libm=no
Packit Service a2489d
      dnl Set REPLACE_FREXPL here because the system may have frexpl in libm.
Packit Service a2489d
      REPLACE_FREXPL=1
Packit Service a2489d
    fi
Packit Service a2489d
    if test $gl_func_frexpl_no_libm = yes; then
Packit Service a2489d
      AC_DEFINE([HAVE_FREXPL_IN_LIBC], [1],
Packit Service a2489d
        [Define if the frexpl() function is available in libc.])
Packit Service a2489d
    fi
Packit Service a2489d
  fi
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether frexpl() can be used without linking with libm.
Packit Service a2489d
dnl Set gl_cv_func_frexpl_no_libm to 'yes' or 'no' accordingly.
Packit Service a2489d
AC_DEFUN([gl_CHECK_FREXPL_NO_LIBM],
Packit Service a2489d
[
Packit Service a2489d
  AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
Packit Service a2489d
    [gl_cv_func_frexpl_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
           [[int e; return frexpl (x, &e) > 0;]])],
Packit Service a2489d
        [gl_cv_func_frexpl_no_libm=yes],
Packit Service a2489d
        [gl_cv_func_frexpl_no_libm=no])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether frexpl() works on finite numbers (this fails on
Packit Service a2489d
dnl Mac OS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers
Packit Service a2489d
dnl (this fails on Mac OS X 10.5/i386), and also on infinite numbers (this
Packit Service a2489d
dnl fails e.g. on IRIX 6.5 and mingw).
Packit Service a2489d
AC_DEFUN([gl_FUNC_FREXPL_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 frexpl works], [gl_cv_func_frexpl_works],
Packit Service a2489d
    [
Packit Service a2489d
      AC_RUN_IFELSE(
Packit Service a2489d
        [AC_LANG_SOURCE([[
Packit Service a2489d
#include <float.h>
Packit Service a2489d
#include <math.h>
Packit Service a2489d
/* Override the values of <float.h>, like done in float.in.h.  */
Packit Service a2489d
#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
Packit Service a2489d
# undef LDBL_MIN_EXP
Packit Service a2489d
# define LDBL_MIN_EXP    (-16381)
Packit Service a2489d
#endif
Packit Service a2489d
#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
Packit Service a2489d
# undef LDBL_MIN_EXP
Packit Service a2489d
# define LDBL_MIN_EXP    (-16381)
Packit Service a2489d
#endif
Packit Service a2489d
#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
Packit Service a2489d
# undef LDBL_MIN_EXP
Packit Service a2489d
# define LDBL_MIN_EXP DBL_MIN_EXP
Packit Service a2489d
#endif
Packit Service a2489d
#if defined __sgi && (LDBL_MANT_DIG >= 106)
Packit Service a2489d
# if defined __GNUC__
Packit Service a2489d
#  undef LDBL_MIN_EXP
Packit Service a2489d
#  define LDBL_MIN_EXP DBL_MIN_EXP
Packit Service a2489d
# endif
Packit Service a2489d
#endif
Packit Service a2489d
extern
Packit Service a2489d
#ifdef __cplusplus
Packit Service a2489d
"C"
Packit Service a2489d
#endif
Packit Service a2489d
long double frexpl (long double, int *);
Packit Service a2489d
int main()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
  volatile long double x;
Packit Service a2489d
  /* Test on finite numbers that fails on AIX 5.1.  */
Packit Service a2489d
  x = 16.0L;
Packit Service a2489d
  {
Packit Service a2489d
    int exp = -9999;
Packit Service a2489d
    frexpl (x, &exp);
Packit Service a2489d
    if (exp != 5)
Packit Service a2489d
      result |= 1;
Packit Service a2489d
  }
Packit Service a2489d
  /* Test on finite numbers that fails on Mac OS X 10.4, because its frexpl
Packit Service a2489d
     function returns an invalid (incorrectly normalized) value: it returns
Packit Service a2489d
               y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 }
Packit Service a2489d
     but the correct result is
Packit Service a2489d
          0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 }  */
Packit Service a2489d
  x = 1.01L;
Packit Service a2489d
  {
Packit Service a2489d
    int exp = -9999;
Packit Service a2489d
    long double y = frexpl (x, &exp);
Packit Service a2489d
    if (!(exp == 1 && y == 0.505L))
Packit Service a2489d
      result |= 2;
Packit Service a2489d
  }
Packit Service a2489d
  /* Test on large finite numbers.  This fails on BeOS at i = 16322, while
Packit Service a2489d
     LDBL_MAX_EXP = 16384.
Packit Service a2489d
     In the loop end test, we test x against Infinity, rather than comparing
Packit Service a2489d
     i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP.  */
Packit Service a2489d
  {
Packit Service a2489d
    int i;
Packit Service a2489d
    for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L)
Packit Service a2489d
      {
Packit Service a2489d
        int exp = -9999;
Packit Service a2489d
        frexpl (x, &exp);
Packit Service a2489d
        if (exp != i)
Packit Service a2489d
          {
Packit Service a2489d
            result |= 4;
Packit Service a2489d
            break;
Packit Service a2489d
          }
Packit Service a2489d
      }
Packit Service a2489d
  }
Packit Service a2489d
  /* Test on denormalized numbers.  */
Packit Service a2489d
  {
Packit Service a2489d
    int i;
Packit Service a2489d
    for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
Packit Service a2489d
      ;
Packit Service a2489d
    if (x > 0.0L)
Packit Service a2489d
      {
Packit Service a2489d
        int exp;
Packit Service a2489d
        long double y = frexpl (x, &exp);
Packit Service a2489d
        /* On machines with IEEE854 arithmetic: x = 1.68105e-4932,
Packit Service a2489d
           exp = -16382, y = 0.5.  On Mac OS X 10.5: exp = -16384, y = 0.5.  */
Packit Service a2489d
        if (exp != LDBL_MIN_EXP - 1)
Packit Service a2489d
          result |= 8;
Packit Service a2489d
      }
Packit Service a2489d
  }
Packit Service a2489d
  /* Test on infinite numbers.  */
Packit Service a2489d
  x = 1.0L / 0.0L;
Packit Service a2489d
  {
Packit Service a2489d
    int exp;
Packit Service a2489d
    long double y = frexpl (x, &exp);
Packit Service a2489d
    if (y != x)
Packit Service a2489d
      result |= 16;
Packit Service a2489d
  }
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_frexpl_works=yes],
Packit Service a2489d
        [gl_cv_func_frexpl_works=no],
Packit Service a2489d
        [
Packit Service a2489d
changequote(,)dnl
Packit Service a2489d
         case "$host_os" in
Packit Service a2489d
           aix | aix[3-6]* | beos* | darwin* | irix* | mingw* | pw*)
Packit Service a2489d
              gl_cv_func_frexpl_works="guessing no";;
Packit Service a2489d
           *) gl_cv_func_frexpl_works="guessing yes";;
Packit Service a2489d
         esac
Packit Service a2489d
changequote([,])dnl
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])