2 dnl Copyright (C) 2007-2008 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) __builtin_isnanf ((float)(x))
41 # define isnanf(x) isnan ((float)(x))
45 [gl_cv_func_isnanf_no_libm=yes],
46 [gl_cv_func_isnanf_no_libm=no])
50 dnl Test whether isnanf() recognizes a NaN (this fails on IRIX 6.5) and rejects
51 dnl Infinity (this fails on Solaris 2.5.1).
52 AC_DEFUN([gl_ISNANF_WORKS],
54 AC_REQUIRE([AC_PROG_CC])
55 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
56 AC_CACHE_CHECK([whether isnan(float) works], [gl_cv_func_isnanf_works],
62 # define isnanf(x) __builtin_isnanf ((float)(x))
65 # define isnanf(x) isnan ((float)(x))
67 /* The Compaq (ex-DEC) C 6.4 compiler chokes on the expression 0.0 / 0.0. */
72 static float zero = 0.0f;
76 # define NaN() (0.0f / 0.0f)
82 if (isnanf (1.0f / 0.0f))
85 }], [gl_cv_func_isnanf_works=yes], [gl_cv_func_isnanf_works=no],
87 irix* | solaris*) gl_cv_func_isnanf_works="guessing no";;
88 *) gl_cv_func_isnanf_works="guessing yes";;
94 AC_DEFUN([gl_FLOAT_EXPONENT_LOCATION],
96 AC_CACHE_CHECK([where to find the exponent in a 'float'],
97 [gl_cv_cc_float_expbit0],
105 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
106 typedef union { float value; unsigned int word[NWORDS]; } memory_float;
107 static unsigned int ored_words[NWORDS];
108 static unsigned int anded_words[NWORDS];
109 static void add_to_ored_words (float x)
113 /* Clear it first, in case
114 sizeof (float) < sizeof (memory_float). */
115 memset (&m, 0, sizeof (memory_float));
117 for (i = 0; i < NWORDS; i++)
119 ored_words[i] |= m.word[i];
120 anded_words[i] &= m.word[i];
126 FILE *fp = fopen ("conftest.out", "w");
129 for (j = 0; j < NWORDS; j++)
130 anded_words[j] = ~ (unsigned int) 0;
131 add_to_ored_words (0.25f);
132 add_to_ored_words (0.5f);
133 add_to_ored_words (1.0f);
134 add_to_ored_words (2.0f);
135 add_to_ored_words (4.0f);
136 /* Remove bits that are common (e.g. if representation of the first mantissa
138 for (j = 0; j < NWORDS; j++)
139 ored_words[j] &= ~anded_words[j];
140 /* Now find the nonzero word. */
141 for (j = 0; j < NWORDS; j++)
142 if (ored_words[j] != 0)
147 for (i = j + 1; i < NWORDS; i++)
148 if (ored_words[i] != 0)
150 fprintf (fp, "unknown");
151 return (fclose (fp) != 0);
154 if ((ored_words[j] >> i) & 1)
156 fprintf (fp, "word %d bit %d", (int) j, (int) i);
157 return (fclose (fp) != 0);
160 fprintf (fp, "unknown");
161 return (fclose (fp) != 0);
164 [gl_cv_cc_float_expbit0=`cat conftest.out`],
165 [gl_cv_cc_float_expbit0="unknown"],
166 [gl_cv_cc_float_expbit0="word 0 bit 23"])
169 case "$gl_cv_cc_float_expbit0" in
171 word=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
172 bit=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word.*bit //'`
173 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_WORD], [$word],
174 [Define as the word index where to find the exponent of 'float'.])
175 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_BIT], [$bit],
176 [Define as the bit index in the word where to find bit 0 of the exponent of 'float'.])