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_CHECK_FUNC([isnan],
12 [gl_cv_func_isnan_no_libm=yes],
13 [gl_cv_func_isnan_no_libm=no])
14 if test $gl_cv_func_isnan_no_libm = yes; then
15 AC_DEFINE([HAVE_ISNAN_IN_LIBC], 1,
16 [Define if the isnan() function is available in libc.])
19 gl_DOUBLE_EXPONENT_LOCATION
23 AC_DEFUN([gl_DOUBLE_EXPONENT_LOCATION],
25 AC_CACHE_CHECK([where to find the exponent in a 'double'],
26 [gl_cv_cc_double_expbit0],
34 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
35 typedef union { double value; unsigned int word[NWORDS]; } memory_double;
36 static unsigned int ored_words[NWORDS];
37 static unsigned int anded_words[NWORDS];
38 static void add_to_ored_words (double x)
42 /* Clear it first, in case sizeof (double) < sizeof (memory_double). */
43 memset (&m, 0, sizeof (memory_double));
45 for (i = 0; i < NWORDS; i++)
47 ored_words[i] |= m.word[i];
48 anded_words[i] &= m.word[i];
54 FILE *fp = fopen ("conftest.out", "w");
57 for (j = 0; j < NWORDS; j++)
58 anded_words[j] = ~ (unsigned int) 0;
59 add_to_ored_words (0.25);
60 add_to_ored_words (0.5);
61 add_to_ored_words (1.0);
62 add_to_ored_words (2.0);
63 add_to_ored_words (4.0);
64 /* Remove bits that are common (e.g. if representation of the first mantissa
66 for (j = 0; j < NWORDS; j++)
67 ored_words[j] &= ~anded_words[j];
68 /* Now find the nonzero word. */
69 for (j = 0; j < NWORDS; j++)
70 if (ored_words[j] != 0)
75 for (i = j + 1; i < NWORDS; i++)
76 if (ored_words[i] != 0)
78 fprintf (fp, "unknown");
79 return (fclose (fp) != 0);
82 if ((ored_words[j] >> i) & 1)
84 fprintf (fp, "word %d bit %d", (int) j, (int) i);
85 return (fclose (fp) != 0);
88 fprintf (fp, "unknown");
89 return (fclose (fp) != 0);
92 [gl_cv_cc_double_expbit0=`cat conftest.out`],
93 [gl_cv_cc_double_expbit0="unknown"],
95 dnl On ARM, integer types are stored in little-endian byte order,
96 dnl but floats are stored in big-endian word order.
97 AC_EGREP_CPP([mixed_endianness], [
98 #if defined arm || defined __arm || defined __arm__
102 [gl_cv_cc_double_expbit0="word 0 bit 20"],
105 [gl_cv_cc_double_expbit0="word 0 bit 20"],
106 [gl_cv_cc_double_expbit0="word 1 bit 20"],
107 [gl_cv_cc_double_expbit0="unknown"])
112 case "$gl_cv_cc_double_expbit0" in
114 word=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
115 bit=`echo "$gl_cv_cc_double_expbit0" | sed -e 's/word.*bit //'`
116 AC_DEFINE_UNQUOTED([DBL_EXPBIT0_WORD], [$word],
117 [Define as the word index where to find the exponent of 'double'.])
118 AC_DEFINE_UNQUOTED([DBL_EXPBIT0_BIT], [$bit],
119 [Define as the bit index in the word where to find bit 0 of the exponent of 'double'.])