remainderf-ieee: Work around test failure on OSF/1.
[gnulib.git] / m4 / signbit.m4
index c6a3891..8955326 100644 (file)
@@ -1,5 +1,5 @@
-# signbit.m4 serial 8
-dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
+# signbit.m4 serial 11
+dnl Copyright (C) 2007-2012 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.
@@ -58,16 +58,14 @@ AC_DEFUN([gl_SIGNBIT],
     REPLACE_SIGNBIT_USING_GCC=1
   else
     if test "$gl_cv_func_signbit" != yes; then
+      dnl REPLACE_SIGNBIT=1 makes sure the signbit[fdl] functions get built.
       REPLACE_SIGNBIT=1
-      AC_LIBOBJ([signbitf])
-      AC_LIBOBJ([signbitd])
-      AC_LIBOBJ([signbitl])
       gl_FLOAT_SIGN_LOCATION
       gl_DOUBLE_SIGN_LOCATION
       gl_LONG_DOUBLE_SIGN_LOCATION
       if test "$gl_cv_cc_float_signbit" = unknown; then
         dnl Test whether copysignf() is declared.
-        AC_CHECK_DECLS([copysignf], , , [#include <math.h>])
+        AC_CHECK_DECLS([copysignf], , , [[#include <math.h>]])
         if test "$ac_cv_have_decl_copysignf" = yes; then
           dnl Test whether copysignf() can be used without libm.
           AC_CACHE_CHECK([whether copysignf can be used without linking with libm],
@@ -89,7 +87,7 @@ AC_DEFUN([gl_SIGNBIT],
       fi
       if test "$gl_cv_cc_double_signbit" = unknown; then
         dnl Test whether copysign() is declared.
-        AC_CHECK_DECLS([copysign], , , [#include <math.h>])
+        AC_CHECK_DECLS([copysign], , , [[#include <math.h>]])
         if test "$ac_cv_have_decl_copysign" = yes; then
           dnl Test whether copysign() can be used without libm.
           AC_CACHE_CHECK([whether copysign can be used without linking with libm],
@@ -111,7 +109,7 @@ AC_DEFUN([gl_SIGNBIT],
       fi
       if test "$gl_cv_cc_long_double_signbit" = unknown; then
         dnl Test whether copysignl() is declared.
-        AC_CHECK_DECLS([copysignl], , , [#include <math.h>])
+        AC_CHECK_DECLS([copysignl], , , [[#include <math.h>]])
         if test "$ac_cv_have_decl_copysignl" = yes; then
           dnl Test whether copysignl() can be used without libm.
           AC_CACHE_CHECK([whether copysignl can be used without linking with libm],
@@ -306,3 +304,43 @@ int main ()
       ;;
   esac
 ])
+
+# Expands to code that defines a function signbitf(float).
+# It extracts the sign bit of a non-NaN value.
+AC_DEFUN([gl_FLOAT_SIGNBIT_CODE],
+[
+  gl_FLOATTYPE_SIGNBIT_CODE([float], [f], [f])
+])
+
+# Expands to code that defines a function signbitd(double).
+# It extracts the sign bit of a non-NaN value.
+AC_DEFUN([gl_DOUBLE_SIGNBIT_CODE],
+[
+  gl_FLOATTYPE_SIGNBIT_CODE([double], [d], [])
+])
+
+# Expands to code that defines a function signbitl(long double).
+# It extracts the sign bit of a non-NaN value.
+AC_DEFUN([gl_LONG_DOUBLE_SIGNBIT_CODE],
+[
+  gl_FLOATTYPE_SIGNBIT_CODE([long double], [l], [L])
+])
+
+AC_DEFUN([gl_FLOATTYPE_SIGNBIT_CODE],
+[[
+static int
+signbit$2 ($1 value)
+{
+  typedef union { $1 f; unsigned char b[sizeof ($1)]; } float_union;
+  static float_union plus_one = { 1.0$3 };   /* unused bits are zero here */
+  static float_union minus_one = { -1.0$3 }; /* unused bits are zero here */
+  /* Compute the sign bit mask as the XOR of plus_one and minus_one.  */
+  float_union u;
+  unsigned int i;
+  u.f = value;
+  for (i = 0; i < sizeof ($1); i++)
+    if (u.b[i] & (plus_one.b[i] ^ minus_one.b[i]))
+      return 1;
+  return 0;
+}
+]])