+2007-04-06 Bruno Haible <bruno@clisp.org>
+
+ * modules/isnanf-nolibm: New file.
+ * lib/isnanf.h: New file.
+ * lib/isnanf.c: New file.
+ * lib/isnan.c: Consider the USE_FLOAT macro.
+ * m4/isnanf.m4: New file.
+
2007-04-06 Bruno Haible <bruno@clisp.org>
* modules/gettext-h (configure.ac): AC_SUBST LIBINTL and LTLIBINTL.
* m4/isc-posix.m4: New file.
-1998-05-10 Jim Meyering <meyering@ascend.com>
-
- * m4/jm-mktime.m4: Use AM_FUNC_MKTIME, now that it's up to date.
-
-1998-05-09 Jim Meyering <meyering@ascend.com>
-
- * m4/Makefile.am (EXTRA_DIST): Add ssize_t.m4.
- (EXTRA_DIST): Remove mktime.m4, now that the new version is included
- with automake.
-
- * m4/ssize_t.m4: New file.
- * m4/mktime.m4: Remove file -- the new automake has this now.
-
-1998-04-26 Jim Meyering <meyering@ascend.com>
-
- * m4/assert.m4: New file.
- * m4/Makefile.am (EXTRA_DIST): Add assert.m4.
-
-1998-04-05 Jim Meyering <meyering@ascend.com>
-
- * m4/prereq.m4 (jm_PREREQ_REGEX): New macro.
- (jm_PREREQ): Use it here.
-
-1998-03-23 Jim Meyering <meyering@eng.ascend.com>
-
- * m4/inttypes_h.m4: Kludges so I don't have to add HAVE_INTTYPES_H
- in acconfig.h.
-
-1998-03-15 Jim Meyering <meyering@eng.ascend.com>
-
- * m4/prereq.m4: New file.
- * m4/error.m4: New file.
- * m4/Makefile.am (EXTRA_DIST): Add error.m4 and prereq.m4.
-
-1998-02-07 Jim Meyering <meyering@eng.ascend.com>
-
- * m4/getline.m4: Don't set am_cv_func_working_getline before the
- cache-check for the same variable -- that defeated the purpose of
- the test; the test program was never run. This was a problem only
- on systems with losing getline functions -- HP-UX 10.20 is one.
- Reported by Bjorn Helgaas.
-
-1998-02-06 Jim Meyering <meyering@eng.ascend.com>
-
- * m4/Makefile.am (EXTRA_DIST): Add perl.m4.
-
-1998-01-10 Jim Meyering <meyering@na-net.ornl.gov>
-
- * m4/Makefile.am (EXTRA_DIST): Add const.m4.
-
- * m4/const.m4: New file. Use an initializer in this declaration
- typedef int charset[2]; const charset x;
- Reported by Bob Glickstein.
-
-1997-12-21 Jim Meyering <meyering@na-net.ornl.gov>
-
- * m4/chown.m4: Fix reversed types on -1 args to chown.
- From Kaveh Ghazi.
-
-1997-12-14 Jim Meyering <meyering@na-net.ornl.gov>
-
- * m4/check-decl.m4: s/DECLARATION_/DECL_/g.
- Add lseek and memchr.
-
- * m4/decl.m4: s/HAVE_DECLARATION_/HAVE_DECL_/g.
- T.E.Dickey <dickey@clark.net> said that some older preprocessors
- have a 20-character limit on names.
-
-1997-11-30 Jim Meyering <meyering@na-net.ornl.gov>
-
- * m4/inttypes_h.m4: New file.
- * m4/uintmax_t.m4: New file.
- * m4/Makefile.am (EXTRA_DIST): Add inttypes_h.m4 and uintmax_t.m4.
-
-Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
- Free Software Foundation, Inc.
-Copying and distribution of this file, with or without modification,
-are permitted provided the copyright notice and this notice are preserved.
+1998-05-10 Jim Meyering <meyering@ascend.com>
\ No newline at end of file
# endif
# define SIZE SIZEOF_LDBL
# define L_(literal) literal##L
-#else
+#elif ! defined USE_FLOAT
# define FUNC rpl_isnan
# define DOUBLE double
# define MAX_EXP DBL_MAX_EXP
# endif
# define SIZE SIZEOF_DBL
# define L_(literal) literal
+#else /* defined USE_FLOAT */
+# define FUNC rpl_isnanf
+# define DOUBLE float
+# define MAX_EXP FLT_MAX_EXP
+# define MIN_EXP FLT_MIN_EXP
+# if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+# define KNOWN_EXPBIT0_LOCATION
+# define EXPBIT0_WORD FLT_EXPBIT0_WORD
+# define EXPBIT0_BIT FLT_EXPBIT0_BIT
+# endif
+# define SIZE SIZEOF_FLT
+# define L_(literal) literal##f
#endif
#define EXP_MASK ((MAX_EXP - MIN_EXP) | 7)
--- /dev/null
+/* Test for NaN that does not need libm.
+ Copyright (C) 2007 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 2, 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, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
+
+#define USE_FLOAT
+#include "isnan.c"
--- /dev/null
+/* Test for NaN that does not need libm.
+ Copyright (C) 2007 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 2, 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, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#if HAVE_ISNANF_IN_LIBC
+/* Get declaration of isnan macro or (older) isnanf function. */
+# include <math.h>
+# ifdef 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
--- /dev/null
+# isnanf.m4 serial 1
+dnl Copyright (C) 2007 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() without linking with libm.
+
+AC_DEFUN([gl_FUNC_ISNANF_NO_LIBM],
+[
+ gl_HAVE_ISNANF_NO_LIBM
+ if test $gl_cv_func_isnanf_no_libm = yes; then
+ 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
+ fi
+])
+
+dnl Test whether isnanf() can be used without libm.
+AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM],
+[
+ AC_CACHE_CHECK([whether isnan(float) can be used without linking with libm],
+ [gl_cv_func_isnanf_no_libm],
+ [
+ AC_TRY_LINK([#include <math.h>
+ #ifdef isnan
+ # undef isnanf
+ # define isnanf(x) isnan ((float)(x))
+ #endif
+ float x;],
+ [return isnanf (x);],
+ [gl_cv_func_isnanf_no_libm=yes],
+ [gl_cv_func_isnanf_no_libm=no])
+ ])
+])
+
+AC_DEFUN([gl_FLOAT_EXPONENT_LOCATION],
+[
+ AC_CACHE_CHECK([where to find the exponent in a 'float'],
+ [gl_cv_cc_float_expbit0],
+ [
+ AC_TRY_RUN([
+#include <float.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#define NWORDS \
+ ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+typedef union { float value; unsigned int word[NWORDS]; } memory_float;
+static unsigned int ored_words[NWORDS];
+static unsigned int anded_words[NWORDS];
+static void add_to_ored_words (float x)
+{
+ memory_float m;
+ size_t i;
+ /* Clear it first, in case
+ sizeof (float) < sizeof (memory_float). */
+ memset (&m, 0, sizeof (memory_float));
+ m.value = x;
+ for (i = 0; i < NWORDS; i++)
+ {
+ ored_words[i] |= m.word[i];
+ anded_words[i] &= m.word[i];
+ }
+}
+int main ()
+{
+ size_t j;
+ FILE *fp = fopen ("conftest.out", "w");
+ if (fp == NULL)
+ return 1;
+ for (j = 0; j < NWORDS; j++)
+ anded_words[j] = ~ (unsigned int) 0;
+ add_to_ored_words (0.25f);
+ add_to_ored_words (0.5f);
+ add_to_ored_words (1.0f);
+ add_to_ored_words (2.0f);
+ add_to_ored_words (4.0f);
+ /* Remove bits that are common (e.g. if representation of the first mantissa
+ bit is explicit). */
+ for (j = 0; j < NWORDS; j++)
+ ored_words[j] &= ~anded_words[j];
+ /* Now find the nonzero word. */
+ for (j = 0; j < NWORDS; j++)
+ if (ored_words[j] != 0)
+ break;
+ if (j < NWORDS)
+ {
+ size_t i;
+ for (i = j + 1; i < NWORDS; i++)
+ if (ored_words[i] != 0)
+ {
+ fprintf (fp, "unknown");
+ return (fclose (fp) != 0);
+ }
+ for (i = 0; ; i++)
+ if ((ored_words[j] >> i) & 1)
+ {
+ fprintf (fp, "word %d bit %d", (int) j, (int) i);
+ return (fclose (fp) != 0);
+ }
+ }
+ fprintf (fp, "unknown");
+ return (fclose (fp) != 0);
+}
+ ],
+ [gl_cv_cc_float_expbit0=`cat conftest.out`],
+ [gl_cv_cc_float_expbit0="unknown"],
+ [gl_cv_cc_double_expbit0="word 0 bit 23"])
+ rm -f conftest.out
+ ])
+ case "$gl_cv_cc_float_expbit0" in
+ word*bit*)
+ word=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
+ bit=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word.*bit //'`
+ AC_DEFINE_UNQUOTED([FLT_EXPBIT0_WORD], [$word],
+ [Define as the word index where to find the exponent of 'float'.])
+ AC_DEFINE_UNQUOTED([FLT_EXPBIT0_BIT], [$bit],
+ [Define as the bit index in the word where to find bit 0 of the exponent of 'float'.])
+ ;;
+ esac
+])
--- /dev/null
+Description:
+isnanf() function: test for NaN, without requiring libm.
+
+Files:
+lib/isnanf.h
+lib/isnanf.c
+lib/isnan.c
+lib/float+.h
+m4/isnanf.m4
+
+Depends-on:
+fpieee
+
+configure.ac:
+gl_FUNC_ISNANF_NO_LIBM
+
+Makefile.am:
+
+Include:
+#include "isnanf.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+