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 isnanf() without linking with libm.
9 AC_DEFUN([gl_FUNC_ISNANF_NO_LIBM],
11 gl_HAVE_ISNANF_NO_LIBM
12 if test $gl_cv_func_isnanf_no_libm = yes; then
15 if test $gl_cv_func_isnanf_no_libm = yes \
16 && test "$gl_cv_func_isnanf_works" = yes; then
17 AC_DEFINE([HAVE_ISNANF_IN_LIBC], 1,
18 [Define if the isnan(float) function is available in libc.])
21 gl_FLOAT_EXPONENT_LOCATION
25 dnl Test whether isnanf() can be used without libm.
26 AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM],
28 AC_CACHE_CHECK([whether isnan(float) can be used without linking with libm],
29 [gl_cv_func_isnanf_no_libm],
31 AC_TRY_LINK([#include <math.h>
34 # define isnanf(x) isnan ((float)(x))
38 [gl_cv_func_isnanf_no_libm=yes],
39 [gl_cv_func_isnanf_no_libm=no])
43 dnl Test whether isnanf() recognizes a NaN (this fails on IRIX 6.5) and rejects
44 dnl Infinity (this fails on Solaris 2.5.1).
45 AC_DEFUN([gl_ISNANF_WORKS],
47 AC_REQUIRE([AC_PROG_CC])
48 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
49 AC_CACHE_CHECK([whether isnan(float) works], [gl_cv_func_isnanf_works],
55 # define isnanf(x) isnan ((float)(x))
57 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
62 static float zero = 0.0f;
66 # define NaN() (0.0f / 0.0f)
72 if (isnanf (1.0f / 0.0f))
75 }], [gl_cv_func_isnanf_works=yes], [gl_cv_func_isnanf_works=no],
77 irix* | solaris*) gl_cv_func_isnanf_works="guessing no";;
78 *) gl_cv_func_isnanf_works="guessing yes";;
84 AC_DEFUN([gl_FLOAT_EXPONENT_LOCATION],
86 AC_CACHE_CHECK([where to find the exponent in a 'float'],
87 [gl_cv_cc_float_expbit0],
95 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
96 typedef union { float value; unsigned int word[NWORDS]; } memory_float;
97 static unsigned int ored_words[NWORDS];
98 static unsigned int anded_words[NWORDS];
99 static void add_to_ored_words (float x)
103 /* Clear it first, in case
104 sizeof (float) < sizeof (memory_float). */
105 memset (&m, 0, sizeof (memory_float));
107 for (i = 0; i < NWORDS; i++)
109 ored_words[i] |= m.word[i];
110 anded_words[i] &= m.word[i];
116 FILE *fp = fopen ("conftest.out", "w");
119 for (j = 0; j < NWORDS; j++)
120 anded_words[j] = ~ (unsigned int) 0;
121 add_to_ored_words (0.25f);
122 add_to_ored_words (0.5f);
123 add_to_ored_words (1.0f);
124 add_to_ored_words (2.0f);
125 add_to_ored_words (4.0f);
126 /* Remove bits that are common (e.g. if representation of the first mantissa
128 for (j = 0; j < NWORDS; j++)
129 ored_words[j] &= ~anded_words[j];
130 /* Now find the nonzero word. */
131 for (j = 0; j < NWORDS; j++)
132 if (ored_words[j] != 0)
137 for (i = j + 1; i < NWORDS; i++)
138 if (ored_words[i] != 0)
140 fprintf (fp, "unknown");
141 return (fclose (fp) != 0);
144 if ((ored_words[j] >> i) & 1)
146 fprintf (fp, "word %d bit %d", (int) j, (int) i);
147 return (fclose (fp) != 0);
150 fprintf (fp, "unknown");
151 return (fclose (fp) != 0);
154 [gl_cv_cc_float_expbit0=`cat conftest.out`],
155 [gl_cv_cc_float_expbit0="unknown"],
156 [gl_cv_cc_double_expbit0="word 0 bit 23"])
159 case "$gl_cv_cc_float_expbit0" in
161 word=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
162 bit=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word.*bit //'`
163 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_WORD], [$word],
164 [Define as the word index where to find the exponent of 'float'.])
165 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_BIT], [$bit],
166 [Define as the bit index in the word where to find bit 0 of the exponent of 'float'.])