1 # exponentf.m4 serial 2
2 dnl Copyright (C) 2007-2008, 2010-2018 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.
6 AC_DEFUN([gl_FLOAT_EXPONENT_LOCATION],
8 AC_CACHE_CHECK([where to find the exponent in a 'float'],
9 [gl_cv_cc_float_expbit0],
18 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
19 typedef union { float value; unsigned int word[NWORDS]; } memory_float;
20 static unsigned int ored_words[NWORDS];
21 static unsigned int anded_words[NWORDS];
22 static void add_to_ored_words (float x)
26 /* Clear it first, in case
27 sizeof (float) < sizeof (memory_float). */
28 memset (&m, 0, sizeof (memory_float));
30 for (i = 0; i < NWORDS; i++)
32 ored_words[i] |= m.word[i];
33 anded_words[i] &= m.word[i];
39 FILE *fp = fopen ("conftest.out", "w");
42 for (j = 0; j < NWORDS; j++)
43 anded_words[j] = ~ (unsigned int) 0;
44 add_to_ored_words (0.25f);
45 add_to_ored_words (0.5f);
46 add_to_ored_words (1.0f);
47 add_to_ored_words (2.0f);
48 add_to_ored_words (4.0f);
49 /* Remove bits that are common (e.g. if representation of the first mantissa
51 for (j = 0; j < NWORDS; j++)
52 ored_words[j] &= ~anded_words[j];
53 /* Now find the nonzero word. */
54 for (j = 0; j < NWORDS; j++)
55 if (ored_words[j] != 0)
60 for (i = j + 1; i < NWORDS; i++)
61 if (ored_words[i] != 0)
63 fprintf (fp, "unknown");
64 return (fclose (fp) != 0);
67 if ((ored_words[j] >> i) & 1)
69 fprintf (fp, "word %d bit %d", (int) j, (int) i);
70 return (fclose (fp) != 0);
73 fprintf (fp, "unknown");
74 return (fclose (fp) != 0);
77 [gl_cv_cc_float_expbit0=`cat conftest.out`],
78 [gl_cv_cc_float_expbit0="unknown"],
79 [gl_cv_cc_float_expbit0="word 0 bit 23"])
82 case "$gl_cv_cc_float_expbit0" in
84 word=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
85 bit=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word.*bit //'`
86 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_WORD], [$word],
87 [Define as the word index where to find the exponent of 'float'.])
88 AC_DEFINE_UNQUOTED([FLT_EXPBIT0_BIT], [$bit],
89 [Define as the bit index in the word where to find bit 0 of the exponent of 'float'.])