view m4/frexp.m4 @ 13834:108bbfd6f03b

frexp, tests: work around ICC bug with -zero * m4/frexp.m4 (gl_FUNC_FREXP_WORKS): Compute -0.0 in a way that works with more compilers. * tests/minus-zero.h: New file. * modules/ceilf-tests (Files): Include it. * modules/ceill-tests (Files): Likewise. * modules/floorf-tests (Files): Likewise. * modules/floorl-tests (Files): Likewise. * modules/frexp-nolibm-tests (Files): Likewise. * modules/frexp-tests (Files): Likewise. * modules/frexpl-nolibm-tests (Files): Likewise. * modules/frexpl-tests (Files): Likewise. * modules/isnan-tests (Files): Likewise. * modules/isnand-nolibm-tests (Files): Likewise. * modules/isnand-tests (Files): Likewise. * modules/isnanf-nolibm-tests (Files): Likewise. * modules/isnanf-tests (Files): Likewise. * modules/isnanl-nolibm-tests (Files): Likewise. * modules/isnanl-tests (Files): Likewise. * modules/round-tests (Files): Likewise. * modules/roundf-tests (Files): Likewise. * modules/roundl-tests (Files): Likewise. * modules/ldexpl-tests (Files): Likewise. * modules/signbit-tests (Files): Likewise. * modules/snprintf-posix-tests (Files): Likewise. * modules/sprintf-posix-tests (Files): Likewise. * modules/strtod-tests (Files): Likewise. * modules/trunc-tests (Files): Likewise. * modules/truncf-tests (Files): Likewise. * modules/truncl-tests (Files): Likewise. * modules/vsnprintf-posix-tests (Files): Likewise. * modules/vsprintf-posix-tests (Files): Likewise. * modules/vasnprintf-posix-tests (Files): Likewise. * modules/vasprintf-posix-tests (Files): Likewise. * tests/test-ceilf1.c (main): Use it. * tests/test-ceill.c (main): Likewise. * tests/test-floorf1.c (main): Likewise. * tests/test-floorl.c (main): Likewise. * tests/test-frexp.c (main): Likewise. * tests/test-frexpl.c (main): Likewise. * tests/test-isnan.c (main): Likewise. * tests/test-isnand.h (main): Likewise. * tests/test-isnanf.h (main): Likewise. * tests/test-isnanl.h (main): Likewise. * tests/test-ldexpl.c (main): Likewise. * tests/test-round.c (main): Likewise. * tests/test-roundf.c (main): Likewise. * tests/test-roundl.c (main): Likewise. * tests/test-signbit.c (test_signbitf, test_signbitd) (test_signbitl): Likewise. * tests/test-snprintf-posix.h (test_function): Likewise. * tests/test-sprintf-posix.h (test_function): Likewise. * tests/test-strtod.c (main): Likewise. * tests/test-trunc1.c (main): Likewise. * tests/test-truncf1.c (main): Likewise. * tests/test-truncl.c (main): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Thu, 04 Nov 2010 12:29:27 -0600
parents da9779900713
children d5a74c6ec06b
line wrap: on
line source

# frexp.m4 serial 9
dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_FUNC_FREXP],
[
  AC_REQUIRE([gl_MATH_H_DEFAULTS])
  AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM])
  FREXP_LIBM=
  if test $gl_cv_func_frexp_no_libm = no; then
    AC_CACHE_CHECK([whether frexp() can be used with libm],
      [gl_cv_func_frexp_in_libm],
      [
        save_LIBS="$LIBS"
        LIBS="$LIBS -lm"
        AC_LINK_IFELSE(
          [AC_LANG_PROGRAM(
             [[#include <math.h>
               double x;]],
             [[int e; return frexp (x, &e) > 0;]])],
          [gl_cv_func_frexp_in_libm=yes],
          [gl_cv_func_frexp_in_libm=no])
        LIBS="$save_LIBS"
      ])
    if test $gl_cv_func_frexp_in_libm = yes; then
      FREXP_LIBM=-lm
    fi
  fi
  if test $gl_cv_func_frexp_no_libm = yes \
     || test $gl_cv_func_frexp_in_libm = yes; then
    save_LIBS="$LIBS"
    LIBS="$LIBS $FREXP_LIBM"
    gl_FUNC_FREXP_WORKS
    LIBS="$save_LIBS"
    case "$gl_cv_func_frexp_works" in
      *yes) gl_func_frexp=yes ;;
      *)    gl_func_frexp=no; REPLACE_FREXP=1; FREXP_LIBM= ;;
    esac
  else
    gl_func_frexp=no
  fi
  if test $gl_func_frexp = yes; then
    AC_DEFINE([HAVE_FREXP], [1],
      [Define if the frexp() function is available and works.])
  else
    AC_LIBOBJ([frexp])
  fi
  AC_SUBST([FREXP_LIBM])
])

AC_DEFUN([gl_FUNC_FREXP_NO_LIBM],
[
  AC_REQUIRE([gl_MATH_H_DEFAULTS])
  AC_REQUIRE([gl_CHECK_FREXP_NO_LIBM])
  if test $gl_cv_func_frexp_no_libm = yes; then
    gl_FUNC_FREXP_WORKS
    case "$gl_cv_func_frexp_works" in
      *yes) gl_func_frexp_no_libm=yes ;;
      *)    gl_func_frexp_no_libm=no; REPLACE_FREXP=1 ;;
    esac
  else
    gl_func_frexp_no_libm=no
    dnl Set REPLACE_FREXP here because the system may have frexp in libm.
    REPLACE_FREXP=1
  fi
  if test $gl_func_frexp_no_libm = yes; then
    AC_DEFINE([HAVE_FREXP_IN_LIBC], [1],
      [Define if the frexp() function is available in libc.])
  else
    AC_LIBOBJ([frexp])
  fi
])

dnl Test whether frexp() can be used without linking with libm.
dnl Set gl_cv_func_frexp_no_libm to 'yes' or 'no' accordingly.
AC_DEFUN([gl_CHECK_FREXP_NO_LIBM],
[
  AC_CACHE_CHECK([whether frexp() can be used without linking with libm],
    [gl_cv_func_frexp_no_libm],
    [
      AC_LINK_IFELSE(
        [AC_LANG_PROGRAM(
           [[#include <math.h>
             double x;]],
           [[int e; return frexp (x, &e) > 0;]])],
        [gl_cv_func_frexp_no_libm=yes],
        [gl_cv_func_frexp_no_libm=no])
    ])
])

dnl Test whether frexp() works also on denormalized numbers (this fails e.g. on
dnl NetBSD 3.0), on infinite numbers (this fails e.g. on IRIX 6.5 and mingw),
dnl and on negative zero (this fails e.g. on NetBSD 4.99).
AC_DEFUN([gl_FUNC_FREXP_WORKS],
[
  AC_REQUIRE([AC_PROG_CC])
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  AC_CACHE_CHECK([whether frexp works], [gl_cv_func_frexp_works],
    [
      AC_RUN_IFELSE(
        [AC_LANG_SOURCE([[
#include <float.h>
#include <math.h>
#include <string.h>
/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
   ICC 10.0 has a bug when optimizing the expression -zero.
   The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
   to PowerPC on MacOS X 10.5.  */
#if defined __hpux || defined __sgi || defined __ICC
static double
compute_minus_zero (void)
{
  return -DBL_MIN * DBL_MIN;
}
# define minus_zero compute_minus_zero ()
#else
double minus_zero = -0.0;
#endif
int main()
{
  int i;
  volatile double x;
  double zero = 0.0;
  /* Test on denormalized numbers.  */
  for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
    ;
  if (x > 0.0)
    {
      int exp;
      double y = frexp (x, &exp);
      /* On machines with IEEE754 arithmetic: x = 1.11254e-308, exp = -1022.
         On NetBSD: y = 0.75. Correct: y = 0.5.  */
      if (y != 0.5)
        return 1;
    }
  /* Test on infinite numbers.  */
  x = 1.0 / 0.0;
  {
    int exp;
    double y = frexp (x, &exp);
    if (y != x)
      return 1;
  }
  /* Test on negative zero.  */
  x = minus_zero;
  {
    int exp;
    double y = frexp (x, &exp);
    if (memcmp (&y, &x, sizeof x))
      return 1;
  }
  return 0;
}]])],
        [gl_cv_func_frexp_works=yes],
        [gl_cv_func_frexp_works=no],
        [case "$host_os" in
           netbsd* | irix* | mingw*) gl_cv_func_frexp_works="guessing no";;
           *)                        gl_cv_func_frexp_works="guessing yes";;
         esac
        ])
    ])
])