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
13 AC_DEFINE([HAVE_ISNANF_IN_LIBC], 1,
14 [Define if the isnan(float) function is available in libc.])
17 gl_FLOAT_EXPONENT_LOCATION
21 dnl Test whether isnanf() can be used without libm.
22 AC_DEFUN([gl_HAVE_ISNANF_NO_LIBM],
24 AC_CACHE_CHECK([whether isnan(float) can be used without linking with libm],
25 [gl_cv_func_isnanf_no_libm],
27 AC_TRY_LINK([#include <math.h>
30 # define isnanf(x) isnan ((float)(x))
34 [gl_cv_func_isnanf_no_libm=yes],
35 [gl_cv_func_isnanf_no_libm=no])
39 AC_DEFUN([gl_FLOAT_EXPONENT_LOCATION],
41 AC_CACHE_CHECK([where to find the exponent in a 'float'],
42 [gl_cv_cc_float_expbit0],
50 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
51 typedef union { float value; unsigned int word[NWORDS]; } memory_float;
52 static unsigned int ored_words[NWORDS];
53 static unsigned int anded_words[NWORDS];
54 static void add_to_ored_words (float x)
58 /* Clear it first, in case
59 sizeof (float) < sizeof (memory_float). */
60 memset (&m, 0, sizeof (memory_float));
62 for (i = 0; i < NWORDS; i++)
64 ored_words[i] |= m.word[i];
65 anded_words[i] &= m.word[i];
71 FILE *fp = fopen ("conftest.out", "w");
74 for (j = 0; j < NWORDS; j++)
75 anded_words[j] = ~ (unsigned int) 0;
76 add_to_ored_words (0.25f);
77 add_to_ored_words (0.5f);
78 add_to_ored_words (1.0f);
79 add_to_ored_words (2.0f);
80 add_to_ored_words (4.0f);
81 /* Remove bits that are common (e.g. if representation of the first mantissa
83 for (j = 0; j < NWORDS; j++)
84 ored_words[j] &= ~anded_words[j];
85 /* Now find the nonzero word. */
86 for (j = 0; j < NWORDS; j++)
87 if (ored_words[j] != 0)
92 for (i = j + 1; i < NWORDS; i++)
93 if (ored_words[i] != 0)
95 fprintf (fp, "unknown");
96 return (fclose (fp) != 0);
99 if ((ored_words[j] >> i) & 1)
101 fprintf (fp, "word %d bit %d", (int) j, (int) i);
102 return (fclose (fp) != 0);
105 fprintf (fp, "unknown");
106 return (fclose (fp) != 0);
109 [gl_cv_cc_float_expbit0=`cat conftest.out`],
110 [gl_cv_cc_float_expbit0="unknown"],
111 [gl_cv_cc_double_expbit0="word 0 bit 23"])
114 case "$gl_cv_cc_float_expbit0" in
116 word=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
117 bit=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word.*bit //'`
118 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_WORD], [$word],
119 [Define as the word index where to find the exponent of 'float'.])
120 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_BIT], [$bit],
121 [Define as the bit index in the word where to find bit 0 of the exponent of 'float'.])