Blame m4/isnanl.m4

Packit Service a2489d
# isnanl.m4 serial 20
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_ISNANL],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([gl_MATH_H_DEFAULTS])
Packit Service a2489d
  ISNANL_LIBM=
Packit Service a2489d
  gl_HAVE_ISNANL_NO_LIBM
Packit Service a2489d
  if test $gl_cv_func_isnanl_no_libm = no; then
Packit Service a2489d
    gl_HAVE_ISNANL_IN_LIBM
Packit Service a2489d
    if test $gl_cv_func_isnanl_in_libm = yes; then
Packit Service a2489d
      ISNANL_LIBM=-lm
Packit Service a2489d
    fi
Packit Service a2489d
  fi
Packit Service a2489d
  dnl The variable gl_func_isnanl set here is used by isnan.m4.
Packit Service a2489d
  if test $gl_cv_func_isnanl_no_libm = yes \
Packit Service a2489d
     || test $gl_cv_func_isnanl_in_libm = yes; then
Packit Service a2489d
    save_LIBS="$LIBS"
Packit Service a2489d
    LIBS="$LIBS $ISNANL_LIBM"
Packit Service a2489d
    gl_FUNC_ISNANL_WORKS
Packit Service a2489d
    LIBS="$save_LIBS"
Packit Service a2489d
    case "$gl_cv_func_isnanl_works" in
Packit Service a2489d
      *yes) gl_func_isnanl=yes ;;
Packit Service a2489d
      *)    gl_func_isnanl=no; ISNANL_LIBM= ;;
Packit Service a2489d
    esac
Packit Service a2489d
  else
Packit Service a2489d
    gl_func_isnanl=no
Packit Service a2489d
  fi
Packit Service a2489d
  if test $gl_func_isnanl != yes; then
Packit Service a2489d
    HAVE_ISNANL=0
Packit Service a2489d
  fi
Packit Service a2489d
  AC_SUBST([ISNANL_LIBM])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
AC_DEFUN([gl_FUNC_ISNANL_NO_LIBM],
Packit Service a2489d
[
Packit Service a2489d
  gl_HAVE_ISNANL_NO_LIBM
Packit Service a2489d
  gl_func_isnanl_no_libm=$gl_cv_func_isnanl_no_libm
Packit Service a2489d
  if test $gl_func_isnanl_no_libm = yes; then
Packit Service a2489d
    gl_FUNC_ISNANL_WORKS
Packit Service a2489d
    case "$gl_cv_func_isnanl_works" in
Packit Service a2489d
      *yes) ;;
Packit Service a2489d
      *)    gl_func_isnanl_no_libm=no ;;
Packit Service a2489d
    esac
Packit Service a2489d
  fi
Packit Service a2489d
  if test $gl_func_isnanl_no_libm = yes; then
Packit Service a2489d
    AC_DEFINE([HAVE_ISNANL_IN_LIBC], [1],
Packit Service a2489d
      [Define if the isnan(long double) function is available in libc.])
Packit Service a2489d
  fi
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Prerequisites of replacement isnanl definition. It does not need -lm.
Packit Service a2489d
AC_DEFUN([gl_PREREQ_ISNANL],
Packit Service a2489d
[
Packit Service a2489d
  gl_LONG_DOUBLE_EXPONENT_LOCATION
Packit Service a2489d
  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether isnanl() can be used without libm.
Packit Service a2489d
AC_DEFUN([gl_HAVE_ISNANL_NO_LIBM],
Packit Service a2489d
[
Packit Service a2489d
  AC_CACHE_CHECK([whether isnan(long double) can be used without linking with libm],
Packit Service a2489d
    [gl_cv_func_isnanl_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
             #if __GNUC__ >= 4
Packit Service a2489d
             # undef isnanl
Packit Service a2489d
             # define isnanl(x) __builtin_isnanl ((long double)(x))
Packit Service a2489d
             #elif defined isnan
Packit Service a2489d
             # undef isnanl
Packit Service a2489d
             # define isnanl(x) isnan ((long double)(x))
Packit Service a2489d
             #endif
Packit Service a2489d
             long double x;]],
Packit Service a2489d
           [[return isnanl (x);]])],
Packit Service a2489d
        [gl_cv_func_isnanl_no_libm=yes],
Packit Service a2489d
        [gl_cv_func_isnanl_no_libm=no])
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether isnanl() can be used with libm.
Packit Service a2489d
AC_DEFUN([gl_HAVE_ISNANL_IN_LIBM],
Packit Service a2489d
[
Packit Service a2489d
  AC_CACHE_CHECK([whether isnan(long double) can be used with libm],
Packit Service a2489d
    [gl_cv_func_isnanl_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
             #if __GNUC__ >= 4
Packit Service a2489d
             # undef isnanl
Packit Service a2489d
             # define isnanl(x) __builtin_isnanl ((long double)(x))
Packit Service a2489d
             #elif defined isnan
Packit Service a2489d
             # undef isnanl
Packit Service a2489d
             # define isnanl(x) isnan ((long double)(x))
Packit Service a2489d
             #endif
Packit Service a2489d
             long double x;]],
Packit Service a2489d
           [[return isnanl (x);]])],
Packit Service a2489d
        [gl_cv_func_isnanl_in_libm=yes],
Packit Service a2489d
        [gl_cv_func_isnanl_in_libm=no])
Packit Service a2489d
      LIBS="$save_LIBS"
Packit Service a2489d
    ])
Packit Service a2489d
])
Packit Service a2489d
Packit Service a2489d
dnl Test whether isnanl() recognizes all canonical numbers which are neither
Packit Service a2489d
dnl finite nor infinite.
Packit Service a2489d
AC_DEFUN([gl_FUNC_ISNANL_WORKS],
Packit Service a2489d
[
Packit Service a2489d
  AC_REQUIRE([AC_PROG_CC])
Packit Service a2489d
  AC_REQUIRE([gl_BIGENDIAN])
Packit Service a2489d
  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
Packit Service a2489d
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service a2489d
  AC_CACHE_CHECK([whether isnanl works], [gl_cv_func_isnanl_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 <limits.h>
Packit Service a2489d
#include <math.h>
Packit Service a2489d
#if __GNUC__ >= 4
Packit Service a2489d
# undef isnanl
Packit Service a2489d
# define isnanl(x) __builtin_isnanl ((long double)(x))
Packit Service a2489d
#elif defined isnan
Packit Service a2489d
# undef isnanl
Packit Service a2489d
# define isnanl(x) isnan ((long double)(x))
Packit Service a2489d
#endif
Packit Service a2489d
#define NWORDS \
Packit Service a2489d
  ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
Packit Service a2489d
typedef union { unsigned int word[NWORDS]; long double value; }
Packit Service a2489d
        memory_long_double;
Packit Service a2489d
/* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
Packit Service a2489d
   runtime type conversion.  */
Packit Service a2489d
#ifdef __sgi
Packit Service a2489d
static long double NaNl ()
Packit Service a2489d
{
Packit Service a2489d
  double zero = 0.0;
Packit Service a2489d
  return zero / zero;
Packit Service a2489d
}
Packit Service a2489d
#else
Packit Service a2489d
# define NaNl() (0.0L / 0.0L)
Packit Service a2489d
#endif
Packit Service a2489d
int main ()
Packit Service a2489d
{
Packit Service a2489d
  int result = 0;
Packit Service a2489d
Packit Service a2489d
  if (!isnanl (NaNl ()))
Packit Service a2489d
    result |= 1;
Packit Service a2489d
Packit Service a2489d
  {
Packit Service a2489d
    memory_long_double m;
Packit Service a2489d
    unsigned int i;
Packit Service a2489d
Packit Service a2489d
    /* The isnanl function should be immune against changes in the sign bit and
Packit Service a2489d
       in the mantissa bits.  The xor operation twiddles a bit that can only be
Packit Service a2489d
       a sign bit or a mantissa bit (since the exponent never extends to
Packit Service a2489d
       bit 31).  */
Packit Service a2489d
    m.value = NaNl ();
Packit Service a2489d
    m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
Packit Service a2489d
    for (i = 0; i < NWORDS; i++)
Packit Service a2489d
      m.word[i] |= 1;
Packit Service a2489d
    if (!isnanl (m.value))
Packit Service a2489d
      result |= 1;
Packit Service a2489d
  }
Packit Service a2489d
Packit Service a2489d
#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
Packit Service a2489d
/* Representation of an 80-bit 'long double' as an initializer for a sequence
Packit Service a2489d
   of 'unsigned int' words.  */
Packit Service a2489d
# ifdef WORDS_BIGENDIAN
Packit Service a2489d
#  define LDBL80_WORDS(exponent,manthi,mantlo) \
Packit Service a2489d
     { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
Packit Service a2489d
       ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
Packit Service a2489d
       (unsigned int) (mantlo) << 16                                        \
Packit Service a2489d
     }
Packit Service a2489d
# else
Packit Service a2489d
#  define LDBL80_WORDS(exponent,manthi,mantlo) \
Packit Service a2489d
     { mantlo, manthi, exponent }
Packit Service a2489d
# endif
Packit Service a2489d
  { /* Quiet NaN.  */
Packit Service a2489d
    static memory_long_double x =
Packit Service a2489d
      { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
Packit Service a2489d
    if (!isnanl (x.value))
Packit Service a2489d
      result |= 2;
Packit Service a2489d
  }
Packit Service a2489d
  {
Packit Service a2489d
    /* Signalling NaN.  */
Packit Service a2489d
    static memory_long_double x =
Packit Service a2489d
      { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
Packit Service a2489d
    if (!isnanl (x.value))
Packit Service a2489d
      result |= 2;
Packit Service a2489d
  }
Packit Service a2489d
  /* isnanl should return something even for noncanonical values.  */
Packit Service a2489d
  { /* Pseudo-NaN.  */
Packit Service a2489d
    static memory_long_double x =
Packit Service a2489d
      { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
Packit Service a2489d
    if (isnanl (x.value) && !isnanl (x.value))
Packit Service a2489d
      result |= 4;
Packit Service a2489d
  }
Packit Service a2489d
  { /* Pseudo-Infinity.  */
Packit Service a2489d
    static memory_long_double x =
Packit Service a2489d
      { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
Packit Service a2489d
    if (isnanl (x.value) && !isnanl (x.value))
Packit Service a2489d
      result |= 8;
Packit Service a2489d
  }
Packit Service a2489d
  { /* Pseudo-Zero.  */
Packit Service a2489d
    static memory_long_double x =
Packit Service a2489d
      { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
Packit Service a2489d
    if (isnanl (x.value) && !isnanl (x.value))
Packit Service a2489d
      result |= 16;
Packit Service a2489d
  }
Packit Service a2489d
  { /* Unnormalized number.  */
Packit Service a2489d
    static memory_long_double x =
Packit Service a2489d
      { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
Packit Service a2489d
    if (isnanl (x.value) && !isnanl (x.value))
Packit Service a2489d
      result |= 32;
Packit Service a2489d
  }
Packit Service a2489d
  { /* Pseudo-Denormal.  */
Packit Service a2489d
    static memory_long_double x =
Packit Service a2489d
      { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
Packit Service a2489d
    if (isnanl (x.value) && !isnanl (x.value))
Packit Service a2489d
      result |= 64;
Packit Service a2489d
  }
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
  return result;
Packit Service a2489d
}]])],
Packit Service a2489d
        [gl_cv_func_isnanl_works=yes],
Packit Service a2489d
        [gl_cv_func_isnanl_works=no],
Packit Service a2489d
        [case "$host_os" in
Packit Service a2489d
           mingw*) # Guess yes on mingw, no on MSVC.
Packit Service a2489d
             AC_EGREP_CPP([Known], [
Packit Service a2489d
#ifdef __MINGW32__
Packit Service a2489d
 Known
Packit Service a2489d
#endif
Packit Service a2489d
               ],
Packit Service a2489d
               [gl_cv_func_isnanl_works="guessing yes"],
Packit Service a2489d
               [gl_cv_func_isnanl_works="guessing no"])
Packit Service a2489d
             ;;
Packit Service a2489d
           *) gl_cv_func_isnanl_works="guessing yes" ;;
Packit Service a2489d
         esac
Packit Service a2489d
        ])
Packit Service a2489d
    ])
Packit Service a2489d
])