summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@cs.stanford.edu>2008-07-12 10:46:03 -0700
committerBen Pfaff <blp@cs.stanford.edu>2008-07-12 11:27:14 -0700
commit4ade019ba68356b5d58a94dccff159a1fde85ad5 (patch)
treeb7d05fb5904a82f6271f284b15029ec67d0e0563
parentfc11af0a623e95f1c0dc57aa56c134e380752770 (diff)
downloadgnulib-4ade019ba68356b5d58a94dccff159a1fde85ad5.tar.gz
Add isnanf module.
-rw-r--r--ChangeLog19
-rwxr-xr-xMODULES.html.sh1
-rw-r--r--doc/glibc-functions/isnanf.texi8
-rw-r--r--lib/isnanf.h33
-rw-r--r--m4/isnanf.m470
-rw-r--r--modules/isnanf30
-rw-r--r--modules/isnanf-nolibm-tests1
-rw-r--r--modules/isnanf-tests15
-rw-r--r--tests/test-isnanf-nolibm.c61
-rw-r--r--tests/test-isnanf.c21
-rw-r--r--tests/test-isnanf.h76
11 files changed, 268 insertions, 67 deletions
diff --git a/ChangeLog b/ChangeLog
index 3a539d02f4..ddc045aaad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
2008-07-10 Ben Pfaff <blp@gnu.org>
+ Add isnanf module.
+ * lib/isnanf.m4: New file.
+ * m4/isnanf.m4 (gl_FUNC_ISNANF): New macro.
+ (gl_HAVE_ISNANF_IN_LIBM): New macro.
+ (gl_BUILD_ISNANF): New macro used by gl_FUNC_ISNANF,
+ gl_FUNC_ISNANF_NO_LIBM, and gl_FUNC_ISNAN.
+ * modules/isnanf: New file.
+ * modules/isnanf-tests: New file.
+ * modules/isnanf-nolibm-tests: Add tests/test-isnanf.h to list of
+ files.
+ * tests/test-isnanf-nolibm.c: factored most of its contents into
+ new file tests/test-isnanf.h.
+ * tests/test-isnanf.h: New file.
+ * tests/test-isnanf.c: New file.
+ * MODULES.html.sh: Mention new module.
+ * doc/glibc-functions/isnanf.texi: Mention new module.
+
+2008-07-10 Ben Pfaff <blp@gnu.org>
+
Add isnand module.
* lib/isnand.h: New file.
* m4/isnand.m4 (gl_FUNC_ISNAND): New macro.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index 6990731d6b..58a19d5c99 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -1999,6 +1999,7 @@ func_all_modules ()
func_module frexpl
func_module frexpl-nolibm
func_module isfinite
+ func_module isnanf
func_module isnanf-nolibm
func_module isnand
func_module isnand-nolibm
diff --git a/doc/glibc-functions/isnanf.texi b/doc/glibc-functions/isnanf.texi
index b1801ffff0..e679fa7d19 100644
--- a/doc/glibc-functions/isnanf.texi
+++ b/doc/glibc-functions/isnanf.texi
@@ -2,15 +2,15 @@
@subsection @code{isnanf}
@findex isnanf
-Gnulib module: ---
+Gnulib module: isnanf
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+MacOS X 10.3, AIX 5.1, HP-UX 11.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-MacOS X 10.3, AIX 5.1, HP-UX 11.
@end itemize
diff --git a/lib/isnanf.h b/lib/isnanf.h
new file mode 100644
index 0000000000..69492e193c
--- /dev/null
+++ b/lib/isnanf.h
@@ -0,0 +1,33 @@
+/* Test for NaN.
+ Copyright (C) 2007-2008 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if HAVE_ISNANF
+/* Get declaration of isnan macro or (older) isnanf function. */
+# include <math.h>
+# if __GNUC__ >= 4
+ /* GCC 4.0 and newer provides three built-ins for isnan. */
+# undef isnanf
+# define isnanf(x) __builtin_isnanf ((float)(x))
+# elif defined isnan
+# undef isnanf
+# define isnanf(x) isnan ((float)(x))
+# endif
+#else
+/* Test whether X is a NaN. */
+# undef isnanf
+# define isnanf rpl_isnanf
+extern int isnanf (float x);
+#endif
diff --git a/m4/isnanf.m4 b/m4/isnanf.m4
index 1338955832..24f72fcf11 100644
--- a/m4/isnanf.m4
+++ b/m4/isnanf.m4
@@ -1,9 +1,43 @@
-# isnanf.m4 serial 6
+# isnanf.m4 serial 7
dnl Copyright (C) 2007-2008 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.
+dnl Check how to get or define isnanf().
+
+AC_DEFUN([gl_FUNC_ISNANF],
+[
+ ISNANF_LIBM=
+ gl_HAVE_ISNANF_NO_LIBM
+ if test $gl_cv_func_isnanf_no_libm = no; then
+ gl_HAVE_ISNANF_IN_LIBM
+ if test $gl_cv_func_isnanf_in_libm = yes; then
+ ISNANF_LIBM=-lm
+ fi
+ fi
+ if test $gl_cv_func_isnanf_no_libm = yes \
+ || test $gl_cv_func_isnanf_in_libm = yes; then
+ save_LIBS="$LIBS"
+ LIBS="$LIBS $ISNANF_LIBM"
+ gl_ISNANF_WORKS
+ LIBS="$save_LIBS"
+ case "$gl_cv_func_isnanf_works" in
+ *yes) gl_func_isnanf=yes ;;
+ *) gl_func_isnanf=no; ISNANF_LIBM= ;;
+ esac
+ else
+ gl_func_isnanf=no
+ fi
+ if test $gl_func_isnanf = yes; then
+ AC_DEFINE([HAVE_ISNANF], 1,
+ [Define if the isnan(float) function is available.])
+ else
+ gl_BUILD_ISNANF
+ fi
+ AC_SUBST([ISNANF_LIBM])
+])
+
dnl Check how to get or define isnanf() without linking with libm.
AC_DEFUN([gl_FUNC_ISNANF_NO_LIBM],
@@ -21,11 +55,17 @@ AC_DEFUN([gl_FUNC_ISNANF_NO_LIBM],
AC_DEFINE([HAVE_ISNANF_IN_LIBC], 1,
[Define if the isnan(float) function is available in libc.])
else
- AC_LIBOBJ([isnanf])
- gl_FLOAT_EXPONENT_LOCATION
+ gl_BUILD_ISNANF
fi
])
+dnl Pull in replacement isnanf definition.
+AC_DEFUN([gl_BUILD_ISNANF],
+[
+ AC_LIBOBJ([isnanf])
+ gl_FLOAT_EXPONENT_LOCATION
+])
+
dnl Test whether isnanf() can be used without libm.
AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM],
[
@@ -47,6 +87,30 @@ AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM],
])
])
+dnl Test whether isnanf() can be used with libm.
+AC_DEFUN([gl_HAVE_ISNANF_IN_LIBM],
+[
+ AC_CACHE_CHECK([whether isnan(float) can be used with libm],
+ [gl_cv_func_isnanf_in_libm],
+ [
+ save_LIBS="$LIBS"
+ LIBS="$LIBS -lm"
+ AC_TRY_LINK([#include <math.h>
+ #if __GNUC__ >= 4
+ # undef isnanf
+ # define isnanf(x) __builtin_isnanf ((float)(x))
+ #elif defined isnan
+ # undef isnanf
+ # define isnanf(x) isnan ((float)(x))
+ #endif
+ float x;],
+ [return isnanf (x);],
+ [gl_cv_func_isnanf_in_libm=yes],
+ [gl_cv_func_isnanf_in_libm=no])
+ LIBS="$save_LIBS"
+ ])
+])
+
dnl Test whether isnanf() rejects Infinity (this fails on Solaris 2.5.1),
dnl recognizes a NaN (this fails on IRIX 6.5 with cc), and recognizes a NaN
dnl with in-memory representation 0x7fbfffff (this fails on IRIX 6.5).
diff --git a/modules/isnanf b/modules/isnanf
new file mode 100644
index 0000000000..72da5370d2
--- /dev/null
+++ b/modules/isnanf
@@ -0,0 +1,30 @@
+Description:
+isnanf() function: test for NaN.
+
+Files:
+lib/isnanf.h
+lib/isnanf.c
+lib/isnan.c
+lib/float+.h
+m4/isnanf.m4
+
+Depends-on:
+fpieee
+
+configure.ac:
+gl_FUNC_ISNANF
+
+Makefile.am:
+
+Include:
+#include "isnanf.h"
+
+Link:
+$(ISNANF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
diff --git a/modules/isnanf-nolibm-tests b/modules/isnanf-nolibm-tests
index 9fba72b71c..0e839302e2 100644
--- a/modules/isnanf-nolibm-tests
+++ b/modules/isnanf-nolibm-tests
@@ -1,5 +1,6 @@
Files:
tests/test-isnanf-nolibm.c
+tests/test-isnanf.h
tests/nan.h
Depends-on:
diff --git a/modules/isnanf-tests b/modules/isnanf-tests
new file mode 100644
index 0000000000..6bd5adc593
--- /dev/null
+++ b/modules/isnanf-tests
@@ -0,0 +1,15 @@
+Files:
+tests/test-isnanf.c
+tests/test-isnanf.h
+tests/nan.h
+
+Depends-on:
+
+configure.ac:
+gl_FLOAT_EXPONENT_LOCATION
+
+Makefile.am:
+TESTS += test-isnanf
+check_PROGRAMS += test-isnanf
+test_isnanf_LDADD = $(LDADD) @ISNANF_LIBM@
+
diff --git a/tests/test-isnanf-nolibm.c b/tests/test-isnanf-nolibm.c
index bbc042a550..0105ce9c04 100644
--- a/tests/test-isnanf-nolibm.c
+++ b/tests/test-isnanf-nolibm.c
@@ -14,67 +14,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
-
#include <config.h>
#include "isnanf-nolibm.h"
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "nan.h"
-
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- fflush (stderr); \
- abort (); \
- } \
- } \
- while (0)
-
-int
-main ()
-{
- /* Finite values. */
- ASSERT (!isnanf (3.141f));
- ASSERT (!isnanf (3.141e30f));
- ASSERT (!isnanf (3.141e-30f));
- ASSERT (!isnanf (-2.718f));
- ASSERT (!isnanf (-2.718e30f));
- ASSERT (!isnanf (-2.718e-30f));
- ASSERT (!isnanf (0.0f));
- ASSERT (!isnanf (-0.0f));
- /* Infinite values. */
- ASSERT (!isnanf (1.0f / 0.0f));
- ASSERT (!isnanf (-1.0f / 0.0f));
- /* Quiet NaN. */
- ASSERT (isnanf (NaNf ()));
-#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
- /* Signalling NaN. */
- {
- #define NWORDS \
- ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
- typedef union { float value; unsigned int word[NWORDS]; } memory_float;
- memory_float m;
- m.value = NaNf ();
-# if FLT_EXPBIT0_BIT > 0
- m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
-# else
- m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
- ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
-# endif
- if (FLT_EXPBIT0_WORD < NWORDS / 2)
- m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
- else
- m.word[0] |= (unsigned int) 1;
- ASSERT (isnanf (m.value));
- }
-#endif
- return 0;
-}
+#include "test-isnanf.h"
diff --git a/tests/test-isnanf.c b/tests/test-isnanf.c
new file mode 100644
index 0000000000..a606520238
--- /dev/null
+++ b/tests/test-isnanf.c
@@ -0,0 +1,21 @@
+/* Test of isnanf() substitute.
+ Copyright (C) 2007-2008 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "isnanf.h"
+
+#include "test-isnanf.h"
diff --git a/tests/test-isnanf.h b/tests/test-isnanf.h
new file mode 100644
index 0000000000..7f6eb1219e
--- /dev/null
+++ b/tests/test-isnanf.h
@@ -0,0 +1,76 @@
+/* Test of isnanf() substitute.
+ Copyright (C) 2007-2008 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "nan.h"
+
+#define ASSERT(expr) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+ fflush (stderr); \
+ abort (); \
+ } \
+ } \
+ while (0)
+
+int
+main ()
+{
+ /* Finite values. */
+ ASSERT (!isnanf (3.141f));
+ ASSERT (!isnanf (3.141e30f));
+ ASSERT (!isnanf (3.141e-30f));
+ ASSERT (!isnanf (-2.718f));
+ ASSERT (!isnanf (-2.718e30f));
+ ASSERT (!isnanf (-2.718e-30f));
+ ASSERT (!isnanf (0.0f));
+ ASSERT (!isnanf (-0.0f));
+ /* Infinite values. */
+ ASSERT (!isnanf (1.0f / 0.0f));
+ ASSERT (!isnanf (-1.0f / 0.0f));
+ /* Quiet NaN. */
+ ASSERT (isnanf (NaNf ()));
+#if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+ /* Signalling NaN. */
+ {
+ #define NWORDS \
+ ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+ typedef union { float value; unsigned int word[NWORDS]; } memory_float;
+ memory_float m;
+ m.value = NaNf ();
+# if FLT_EXPBIT0_BIT > 0
+ m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
+# else
+ m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
+ ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
+# endif
+ if (FLT_EXPBIT0_WORD < NWORDS / 2)
+ m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
+ else
+ m.word[0] |= (unsigned int) 1;
+ ASSERT (isnanf (m.value));
+ }
+#endif
+ return 0;
+}