bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[1/2] new module 'isinf'


From: Ben Pfaff
Subject: [1/2] new module 'isinf'
Date: Mon, 14 Jul 2008 21:24:35 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

PSPP wants to use 'isinf', so I've written up a new module for
the C99 'isinf' macro.  A preliminary is this patch that factors
out the m4 code for finding exponent bits in floating-point
numbers.  The body of the patch is coming up in part 2/2.

Thanks,

Ben.

commit 2b9c4ebed5360a54355ba9991d5060a0e694d1e0
Author: Ben Pfaff <address@hidden>
Date:   Mon Jul 14 21:21:41 2008 -0700

    Move macros for finding floating-point exponents into separate M4 files.

diff --git a/ChangeLog b/ChangeLog
index 9c79e5d..ac4a511 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2008-07-14  Ben Pfaff  <address@hidden>
+
+       Factor out some macros for use by additional modules.
+       * m4/isnanf.m4 (gl_FLOAT_EXPONENT_LOCATION): Move into new file
+       float-exponent.m4.
+       * m4/isnand.m4 (gl_DOUBLE_EXPONENT_LOCATION): Move into new file
+       double-exponent.m4.
+       * m4/isnanl.m4 (gl_LONG_DOUBLE_EXPONENT_LOCATION): Move into new
+       file ldouble-exponent.m4.
+       * m4/float-exponent.m4: New file.
+       * m4/double-exponent.m4: New file.
+       * m4/ldouble-exponent.m4: New file.
+       * modules/isnanf: Use new file m4/float-exponent.m4.
+       * modules/isnand: Use new file m4/double-exponent.m4.
+       * modules/isnanl: Use new file m4/ldouble-exponent.m4.
+
 2008-07-12  Ben Pfaff  <address@hidden>
 
        Add longlong module.
diff --git a/m4/double-exponent.m4 b/m4/double-exponent.m4
new file mode 100644
index 0000000..a8319f7
--- /dev/null
+++ b/m4/double-exponent.m4
@@ -0,0 +1,114 @@
+# double-exponent.m4 serial 1
+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.
+AC_DEFUN([gl_DOUBLE_EXPONENT_LOCATION],
+[
+  AC_CACHE_CHECK([where to find the exponent in a 'double'],
+    [gl_cv_cc_double_expbit0],
+    [
+      AC_TRY_RUN([
+#include <float.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#define NWORDS \
+  ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+typedef union { double value; unsigned int word[NWORDS]; } memory_double;
+static unsigned int ored_words[NWORDS];
+static unsigned int anded_words[NWORDS];
+static void add_to_ored_words (double x)
+{
+  memory_double m;
+  size_t i;
+  /* Clear it first, in case sizeof (double) < sizeof (memory_double).  */
+  memset (&m, 0, sizeof (memory_double));
+  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.25);
+  add_to_ored_words (0.5);
+  add_to_ored_words (1.0);
+  add_to_ored_words (2.0);
+  add_to_ored_words (4.0);
+  /* 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_double_expbit0=`cat conftest.out`],
+        [gl_cv_cc_double_expbit0="unknown"],
+        [
+          dnl On ARM, there are two 'double' floating-point formats, used by
+          dnl different sets of instructions: The older FPA instructions assume
+          dnl that they are stored in big-endian word order, while the words
+          dnl (like integer types) are stored in little-endian byte order.
+          dnl The newer VFP instructions assume little-endian order 
consistenly.
+          AC_EGREP_CPP([mixed_endianness], [
+#if defined arm || defined __arm || defined __arm__
+  mixed_endianness
+#endif
+            ],
+            [gl_cv_cc_double_expbit0="unknown"],
+            [
+              pushdef([AC_MSG_CHECKING],[:])dnl
+              pushdef([AC_MSG_RESULT],[:])dnl
+              pushdef([AC_MSG_RESULT_UNQUOTED],[:])dnl
+              AC_C_BIGENDIAN(
+                [gl_cv_cc_double_expbit0="word 0 bit 20"],
+                [gl_cv_cc_double_expbit0="word 1 bit 20"],
+                [gl_cv_cc_double_expbit0="unknown"])
+              popdef([AC_MSG_RESULT_UNQUOTED])dnl
+              popdef([AC_MSG_RESULT])dnl
+              popdef([AC_MSG_CHECKING])dnl
+            ])
+        ])
+      rm -f conftest.out
+    ])
+  case "$gl_cv_cc_double_expbit0" in
+    word*bit*)
+      word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ 
bit.*//'`
+      bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'`
+      AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word],
+        [Define as the word index where to find the exponent of 'double'.])
+      AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit],
+        [Define as the bit index in the word where to find bit 0 of the 
exponent of 'double'.])
+      ;;
+  esac
+])
diff --git a/m4/float-exponent.m4 b/m4/float-exponent.m4
new file mode 100644
index 0000000..5759ea5
--- /dev/null
+++ b/m4/float-exponent.m4
@@ -0,0 +1,91 @@
+# float-exponent.m4 serial 1
+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.
+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_float_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
+])
diff --git a/m4/isnand.m4 b/m4/isnand.m4
index f21d384..fbb03f8 100644
--- a/m4/isnand.m4
+++ b/m4/isnand.m4
@@ -1,4 +1,4 @@
-# isnand.m4 serial 3
+# isnand.m4 serial 4
 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,
@@ -92,113 +92,3 @@ AC_DEFUN([gl_HAVE_ISNAND_NO_LIBM],
         [gl_cv_func_isnand_no_libm=no])
     ])
 ])
-
-AC_DEFUN([gl_DOUBLE_EXPONENT_LOCATION],
-[
-  AC_CACHE_CHECK([where to find the exponent in a 'double'],
-    [gl_cv_cc_double_expbit0],
-    [
-      AC_TRY_RUN([
-#include <float.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
-#define NWORDS \
-  ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-typedef union { double value; unsigned int word[NWORDS]; } memory_double;
-static unsigned int ored_words[NWORDS];
-static unsigned int anded_words[NWORDS];
-static void add_to_ored_words (double x)
-{
-  memory_double m;
-  size_t i;
-  /* Clear it first, in case sizeof (double) < sizeof (memory_double).  */
-  memset (&m, 0, sizeof (memory_double));
-  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.25);
-  add_to_ored_words (0.5);
-  add_to_ored_words (1.0);
-  add_to_ored_words (2.0);
-  add_to_ored_words (4.0);
-  /* 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_double_expbit0=`cat conftest.out`],
-        [gl_cv_cc_double_expbit0="unknown"],
-        [
-          dnl On ARM, there are two 'double' floating-point formats, used by
-          dnl different sets of instructions: The older FPA instructions assume
-          dnl that they are stored in big-endian word order, while the words
-          dnl (like integer types) are stored in little-endian byte order.
-          dnl The newer VFP instructions assume little-endian order 
consistenly.
-          AC_EGREP_CPP([mixed_endianness], [
-#if defined arm || defined __arm || defined __arm__
-  mixed_endianness
-#endif
-            ],
-            [gl_cv_cc_double_expbit0="unknown"],
-            [
-              pushdef([AC_MSG_CHECKING],[:])dnl
-              pushdef([AC_MSG_RESULT],[:])dnl
-              pushdef([AC_MSG_RESULT_UNQUOTED],[:])dnl
-              AC_C_BIGENDIAN(
-                [gl_cv_cc_double_expbit0="word 0 bit 20"],
-                [gl_cv_cc_double_expbit0="word 1 bit 20"],
-                [gl_cv_cc_double_expbit0="unknown"])
-              popdef([AC_MSG_RESULT_UNQUOTED])dnl
-              popdef([AC_MSG_RESULT])dnl
-              popdef([AC_MSG_CHECKING])dnl
-            ])
-        ])
-      rm -f conftest.out
-    ])
-  case "$gl_cv_cc_double_expbit0" in
-    word*bit*)
-      word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ 
bit.*//'`
-      bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'`
-      AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word],
-        [Define as the word index where to find the exponent of 'double'.])
-      AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit],
-        [Define as the bit index in the word where to find bit 0 of the 
exponent of 'double'.])
-      ;;
-  esac
-])
diff --git a/m4/isnanf.m4 b/m4/isnanf.m4
index de7ebe8..289a49b 100644
--- a/m4/isnanf.m4
+++ b/m4/isnanf.m4
@@ -1,4 +1,4 @@
-# isnanf.m4 serial 7
+# isnanf.m4 serial 8
 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,
@@ -178,90 +178,3 @@ int main()
         ])
     ])
 ])
-
-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_float_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
-])
diff --git a/m4/isnanl.m4 b/m4/isnanl.m4
index 55be261..c2f050f 100644
--- a/m4/isnanl.m4
+++ b/m4/isnanl.m4
@@ -1,4 +1,4 @@
-# isnanl.m4 serial 7
+# isnanl.m4 serial 8
 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,
@@ -234,96 +234,3 @@ int main ()
       ])
     ])
 ])
-
-AC_DEFUN([gl_LONG_DOUBLE_EXPONENT_LOCATION],
-[
-  AC_REQUIRE([AC_C_BIGENDIAN])
-  AC_CACHE_CHECK([where to find the exponent in a 'long double'],
-    [gl_cv_cc_long_double_expbit0],
-    [
-      AC_TRY_RUN([
-#include <float.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
-#define NWORDS \
-  ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-typedef union { long double value; unsigned int word[NWORDS]; }
-        memory_long_double;
-static unsigned int ored_words[NWORDS];
-static unsigned int anded_words[NWORDS];
-static void add_to_ored_words (long double x)
-{
-  memory_long_double m;
-  size_t i;
-  /* Clear it first, in case
-     sizeof (long double) < sizeof (memory_long_double).  */
-  memset (&m, 0, sizeof (memory_long_double));
-  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.25L);
-  add_to_ored_words (0.5L);
-  add_to_ored_words (1.0L);
-  add_to_ored_words (2.0L);
-  add_to_ored_words (4.0L);
-  /* 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_long_double_expbit0=`cat conftest.out`],
-        [gl_cv_cc_long_double_expbit0="unknown"],
-        [
-          dnl When cross-compiling, we don't know. It depends on the
-          dnl ABI and compiler version. There are too many cases.
-          gl_cv_cc_long_double_expbit0="unknown"
-        ])
-      rm -f conftest.out
-    ])
-  case "$gl_cv_cc_long_double_expbit0" in
-    word*bit*)
-      word=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word //' -e 's/ 
bit.*//'`
-      bit=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word.*bit //'`
-      AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_WORD], [$word],
-        [Define as the word index where to find the exponent of 'long 
double'.])
-      AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_BIT], [$bit],
-        [Define as the bit index in the word where to find bit 0 of the 
exponent of 'long double'.])
-      ;;
-  esac
-])
diff --git a/m4/ldouble-exponent.m4 b/m4/ldouble-exponent.m4
new file mode 100644
index 0000000..efaf8d0
--- /dev/null
+++ b/m4/ldouble-exponent.m4
@@ -0,0 +1,97 @@
+# ldouble-exponent.m4 serial 1
+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.
+AC_DEFUN([gl_LONG_DOUBLE_EXPONENT_LOCATION],
+[
+  AC_REQUIRE([AC_C_BIGENDIAN])
+  AC_CACHE_CHECK([where to find the exponent in a 'long double'],
+    [gl_cv_cc_long_double_expbit0],
+    [
+      AC_TRY_RUN([
+#include <float.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#define NWORDS \
+  ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+typedef union { long double value; unsigned int word[NWORDS]; }
+        memory_long_double;
+static unsigned int ored_words[NWORDS];
+static unsigned int anded_words[NWORDS];
+static void add_to_ored_words (long double x)
+{
+  memory_long_double m;
+  size_t i;
+  /* Clear it first, in case
+     sizeof (long double) < sizeof (memory_long_double).  */
+  memset (&m, 0, sizeof (memory_long_double));
+  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.25L);
+  add_to_ored_words (0.5L);
+  add_to_ored_words (1.0L);
+  add_to_ored_words (2.0L);
+  add_to_ored_words (4.0L);
+  /* 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_long_double_expbit0=`cat conftest.out`],
+        [gl_cv_cc_long_double_expbit0="unknown"],
+        [
+          dnl When cross-compiling, we don't know. It depends on the
+          dnl ABI and compiler version. There are too many cases.
+          gl_cv_cc_long_double_expbit0="unknown"
+        ])
+      rm -f conftest.out
+    ])
+  case "$gl_cv_cc_long_double_expbit0" in
+    word*bit*)
+      word=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word //' -e 's/ 
bit.*//'`
+      bit=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word.*bit //'`
+      AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_WORD], [$word],
+        [Define as the word index where to find the exponent of 'long 
double'.])
+      AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_BIT], [$bit],
+        [Define as the bit index in the word where to find bit 0 of the 
exponent of 'long double'.])
+      ;;
+  esac
+])
diff --git a/modules/isnand b/modules/isnand
index ab6cda5..140fb80 100644
--- a/modules/isnand
+++ b/modules/isnand
@@ -6,6 +6,7 @@ lib/isnand.h
 lib/isnand.c
 lib/isnan.c
 lib/float+.h
+m4/double-exponent.m4
 m4/isnand.m4
 
 Depends-on:
diff --git a/modules/isnanf b/modules/isnanf
index 72da537..11d1e8c 100644
--- a/modules/isnanf
+++ b/modules/isnanf
@@ -6,6 +6,7 @@ lib/isnanf.h
 lib/isnanf.c
 lib/isnan.c
 lib/float+.h
+m4/float-exponent.m4
 m4/isnanf.m4
 
 Depends-on:
diff --git a/modules/isnanl b/modules/isnanl
index 026981f..e58a90f 100644
--- a/modules/isnanl
+++ b/modules/isnanl
@@ -6,6 +6,7 @@ lib/isnanl.h
 lib/isnanl.c
 lib/isnan.c
 lib/float+.h
+m4/ldouble-exponent.m4
 m4/isnanl.m4
 
 Depends-on:

-- 
Ben Pfaff 
http://benpfaff.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]