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 && { case "$gl_cv_func_isnanf_works" in
21 AC_DEFINE([HAVE_ISNANF_IN_LIBC], 1,
22 [Define if the isnan(float) function is available in libc.])
25 gl_FLOAT_EXPONENT_LOCATION
29 dnl Test whether isnanf() can be used without libm.
30 AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM],
32 AC_CACHE_CHECK([whether isnan(float) can be used without linking with libm],
33 [gl_cv_func_isnanf_no_libm],
35 AC_TRY_LINK([#include <math.h>
38 # define isnanf(x) isnan ((float)(x))
42 [gl_cv_func_isnanf_no_libm=yes],
43 [gl_cv_func_isnanf_no_libm=no])
47 dnl Test whether isnanf() recognizes a NaN (this fails on IRIX 6.5) and rejects
48 dnl Infinity (this fails on Solaris 2.5.1).
49 AC_DEFUN([gl_ISNANF_WORKS],
51 AC_REQUIRE([AC_PROG_CC])
52 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
53 AC_CACHE_CHECK([whether isnan(float) works], [gl_cv_func_isnanf_works],
59 # define isnanf(x) isnan ((float)(x))
61 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
66 static float zero = 0.0f;
70 # define NaN() (0.0f / 0.0f)
76 if (isnanf (1.0f / 0.0f))
79 }], [gl_cv_func_isnanf_works=yes], [gl_cv_func_isnanf_works=no],
81 irix* | solaris*) gl_cv_func_isnanf_works="guessing no";;
82 *) gl_cv_func_isnanf_works="guessing yes";;
88 AC_DEFUN([gl_FLOAT_EXPONENT_LOCATION],
90 AC_CACHE_CHECK([where to find the exponent in a 'float'],
91 [gl_cv_cc_float_expbit0],
99 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
100 typedef union { float value; unsigned int word[NWORDS]; } memory_float;
101 static unsigned int ored_words[NWORDS];
102 static unsigned int anded_words[NWORDS];
103 static void add_to_ored_words (float x)
107 /* Clear it first, in case
108 sizeof (float) < sizeof (memory_float). */
109 memset (&m, 0, sizeof (memory_float));
111 for (i = 0; i < NWORDS; i++)
113 ored_words[i] |= m.word[i];
114 anded_words[i] &= m.word[i];
120 FILE *fp = fopen ("conftest.out", "w");
123 for (j = 0; j < NWORDS; j++)
124 anded_words[j] = ~ (unsigned int) 0;
125 add_to_ored_words (0.25f);
126 add_to_ored_words (0.5f);
127 add_to_ored_words (1.0f);
128 add_to_ored_words (2.0f);
129 add_to_ored_words (4.0f);
130 /* Remove bits that are common (e.g. if representation of the first mantissa
132 for (j = 0; j < NWORDS; j++)
133 ored_words[j] &= ~anded_words[j];
134 /* Now find the nonzero word. */
135 for (j = 0; j < NWORDS; j++)
136 if (ored_words[j] != 0)
141 for (i = j + 1; i < NWORDS; i++)
142 if (ored_words[i] != 0)
144 fprintf (fp, "unknown");
145 return (fclose (fp) != 0);
148 if ((ored_words[j] >> i) & 1)
150 fprintf (fp, "word %d bit %d", (int) j, (int) i);
151 return (fclose (fp) != 0);
154 fprintf (fp, "unknown");
155 return (fclose (fp) != 0);
158 [gl_cv_cc_float_expbit0=`cat conftest.out`],
159 [gl_cv_cc_float_expbit0="unknown"],
160 [gl_cv_cc_float_expbit0="word 0 bit 23"])
163 case "$gl_cv_cc_float_expbit0" in
165 word=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
166 bit=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word.*bit //'`
167 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_WORD], [$word],
168 [Define as the word index where to find the exponent of 'float'.])
169 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_BIT], [$bit],
170 [Define as the bit index in the word where to find bit 0 of the exponent of 'float'.])