1 # exponentl.m4 serial 5
2 dnl Copyright (C) 2007-2022 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_LONG_DOUBLE_EXPONENT_LOCATION],
8 AC_REQUIRE([gl_BIGENDIAN])
9 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
10 AC_CACHE_CHECK([where to find the exponent in a 'long double'],
11 [gl_cv_cc_long_double_expbit0],
20 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
21 typedef union { long double value; unsigned int word[NWORDS]; }
23 static unsigned int ored_words[NWORDS];
24 static unsigned int anded_words[NWORDS];
25 static void add_to_ored_words (long double *x)
29 /* Clear it first, in case
30 sizeof (long double) < sizeof (memory_long_double). */
31 memset (&m, 0, sizeof (memory_long_double));
33 for (i = 0; i < NWORDS; i++)
35 ored_words[i] |= m.word[i];
36 anded_words[i] &= m.word[i];
41 static long double samples[5] = { 0.25L, 0.5L, 1.0L, 2.0L, 4.0L };
43 FILE *fp = fopen ("conftest.out", "w");
46 for (j = 0; j < NWORDS; j++)
47 anded_words[j] = ~ (unsigned int) 0;
48 for (j = 0; j < 5; j++)
49 add_to_ored_words (&samples[j]);
50 /* Remove bits that are common (e.g. if representation of the first mantissa
52 for (j = 0; j < NWORDS; j++)
53 ored_words[j] &= ~anded_words[j];
54 /* Now find the nonzero word. */
55 for (j = 0; j < NWORDS; j++)
56 if (ored_words[j] != 0)
61 for (i = j + 1; i < NWORDS; i++)
62 if (ored_words[i] != 0)
64 fprintf (fp, "unknown");
65 return (fclose (fp) != 0);
68 if ((ored_words[j] >> i) & 1)
70 fprintf (fp, "word %d bit %d", (int) j, (int) i);
71 return (fclose (fp) != 0);
74 fprintf (fp, "unknown");
75 return (fclose (fp) != 0);
78 [gl_cv_cc_long_double_expbit0=`cat conftest.out`],
79 [gl_cv_cc_long_double_expbit0="unknown"],
81 dnl When cross-compiling, in general we don't know. It depends on the
82 dnl ABI and compiler version. There are too many cases.
83 gl_cv_cc_long_double_expbit0="unknown"
85 mingw*) # On native Windows (little-endian), we know the result
86 # in two cases: mingw, MSVC.
87 AC_EGREP_CPP([Known], [
91 ], [gl_cv_cc_long_double_expbit0="word 2 bit 0"])
92 AC_EGREP_CPP([Known], [
96 ], [gl_cv_cc_long_double_expbit0="word 1 bit 20"])
102 case "$gl_cv_cc_long_double_expbit0" in
104 word=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word //' -e 's/ bit.*//'`
105 bit=`echo "$gl_cv_cc_long_double_expbit0" | sed -e 's/word.*bit //'`
106 AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_WORD], [$word],
107 [Define as the word index where to find the exponent of 'long double'.])
108 AC_DEFINE_UNQUOTED([LDBL_EXPBIT0_BIT], [$bit],
109 [Define as the bit index in the word where to find bit 0 of the exponent of 'long double'.])