2 dnl Copyright (C) 2007 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl Check how to get or define isnan() without linking with libm.
9 AC_DEFUN([gl_FUNC_ISNAN_NO_LIBM],
11 AC_CACHE_CHECK([whether isnan(double) can be used without linking with libm],
12 [gl_cv_func_isnan_no_libm],
14 AC_TRY_LINK([#include <math.h>
17 [gl_cv_func_isnan_no_libm=yes],
18 [gl_cv_func_isnan_no_libm=no])
20 if test $gl_cv_func_isnan_no_libm = yes; then
21 AC_DEFINE([HAVE_ISNAN_IN_LIBC], 1,
22 [Define if the isnan(double) function is available in libc.])
25 gl_DOUBLE_EXPONENT_LOCATION
29 AC_DEFUN([gl_DOUBLE_EXPONENT_LOCATION],
31 AC_CACHE_CHECK([where to find the exponent in a 'double'],
32 [gl_cv_cc_double_expbit0],
40 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
41 typedef union { double value; unsigned int word[NWORDS]; } memory_double;
42 static unsigned int ored_words[NWORDS];
43 static unsigned int anded_words[NWORDS];
44 static void add_to_ored_words (double x)
48 /* Clear it first, in case sizeof (double) < sizeof (memory_double). */
49 memset (&m, 0, sizeof (memory_double));
51 for (i = 0; i < NWORDS; i++)
53 ored_words[i] |= m.word[i];
54 anded_words[i] &= m.word[i];
60 FILE *fp = fopen ("conftest.out", "w");
63 for (j = 0; j < NWORDS; j++)
64 anded_words[j] = ~ (unsigned int) 0;
65 add_to_ored_words (0.25);
66 add_to_ored_words (0.5);
67 add_to_ored_words (1.0);
68 add_to_ored_words (2.0);
69 add_to_ored_words (4.0);
70 /* Remove bits that are common (e.g. if representation of the first mantissa
72 for (j = 0; j < NWORDS; j++)
73 ored_words[j] &= ~anded_words[j];
74 /* Now find the nonzero word. */
75 for (j = 0; j < NWORDS; j++)
76 if (ored_words[j] != 0)
81 for (i = j + 1; i < NWORDS; i++)
82 if (ored_words[i] != 0)
84 fprintf (fp, "unknown");
85 return (fclose (fp) != 0);
88 if ((ored_words[j] >> i) & 1)
90 fprintf (fp, "word %d bit %d", (int) j, (int) i);
91 return (fclose (fp) != 0);
94 fprintf (fp, "unknown");
95 return (fclose (fp) != 0);
98 [gl_cv_cc_double_expbit0=`cat conftest.out`],
99 [gl_cv_cc_double_expbit0="unknown"],
101 dnl On ARM, there are two 'double' floating-point formats, used by
102 dnl different sets of instructions: The older FPA instructions assume
103 dnl that they are stored in big-endian word order, while the words
104 dnl (like integer types) are stored in little-endian byte order.
105 dnl The newer VFP instructions assume little-endian order consistenly.
106 AC_EGREP_CPP([mixed_endianness], [
107 #if defined arm || defined __arm || defined __arm__
111 [gl_cv_cc_double_expbit0="unknown"],
114 [gl_cv_cc_double_expbit0="word 0 bit 20"],
115 [gl_cv_cc_double_expbit0="word 1 bit 20"],
116 [gl_cv_cc_double_expbit0="unknown"])
121 case "$gl_cv_cc_double_expbit0" in
123 word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
124 bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'`
125 AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word],
126 [Define as the word index where to find the exponent of 'double'.])
127 AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit],
128 [Define as the bit index in the word where to find bit 0 of the exponent of 'double'.])