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.
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
10 AC_CACHE_CHECK([for signbit macro], [gl_cv_func_signbit],
19 long double p0l = 0.0L;
20 long double m0l = -0.0L;
24 float plus_inf = 1.0f / p0f;
25 float minus_inf = -1.0f / p0f;
26 if (!(!signbit (255.0f)
29 && (memcmp (&m0f, &p0f, sizeof (float)) == 0 || signbit (m0f))
30 && !signbit (plus_inf)
31 && signbit (minus_inf)))
35 double plus_inf = 1.0 / p0d;
36 double minus_inf = -1.0 / p0d;
37 if (!(!signbit (255.0)
40 && (memcmp (&m0d, &p0d, sizeof (double)) == 0 || signbit (m0d))
41 && !signbit (plus_inf)
42 && signbit (minus_inf)))
46 long double plus_inf = 1.0L / p0l;
47 long double minus_inf = -1.0L / p0l;
48 if (!(!signbit (255.0L)
51 && (memcmp (&m0l, &p0l, sizeof (long double)) == 0 || signbit (m0l))
52 && !signbit (plus_inf)
53 && signbit (minus_inf)))
57 }], [gl_cv_func_signbit=yes], [gl_cv_func_signbit=no],
58 [gl_cv_func_signbit="guessing no"])
60 if test "$gl_cv_func_signbit" != yes; then
65 gl_FLOAT_SIGN_LOCATION
66 gl_DOUBLE_SIGN_LOCATION
67 gl_LONG_DOUBLE_SIGN_LOCATION
71 AC_DEFUN([gl_FLOAT_SIGN_LOCATION],
73 gl_FLOATTYPE_SIGN_LOCATION([float], [gl_cv_cc_float_signbit], [f], [FLT])
76 AC_DEFUN([gl_DOUBLE_SIGN_LOCATION],
78 gl_FLOATTYPE_SIGN_LOCATION([double], [gl_cv_cc_double_signbit], [], [DBL])
81 AC_DEFUN([gl_LONG_DOUBLE_SIGN_LOCATION],
83 gl_FLOATTYPE_SIGN_LOCATION([long double], [gl_cv_cc_long_double_signbit], [L], [LDBL])
86 AC_DEFUN([gl_FLOATTYPE_SIGN_LOCATION],
88 AC_CACHE_CHECK([where to find the sign bit in a '$1'],
95 ((sizeof ($1) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
96 typedef union { $1 value; unsigned int word[NWORDS]; }
98 static memory_float plus = { 1.0$3 };
99 static memory_float minus = { -1.0$3 };
104 FILE *fp = fopen ("conftest.out", "w");
107 /* Find the different bit. */
109 for (j = 0; j < NWORDS; j++)
111 unsigned int x = plus.word[j] ^ minus.word[j];
112 if ((x & (x - 1)) || (x && m))
114 /* More than one bit difference. */
115 fprintf (fp, "unknown");
127 fprintf (fp, "unknown");
130 /* Now m = plus.word[k] ^ ~minus.word[k]. */
131 if (plus.word[k] & ~minus.word[k])
133 /* Oh? The sign bit is set in the positive and cleared in the negative
135 fprintf (fp, "unknown");
141 fprintf (fp, "word %d bit %d", (int) k, (int) i);
142 return (fclose (fp) != 0);
145 [$2=`cat conftest.out`],
148 dnl When cross-compiling, we don't know. It depends on the
149 dnl ABI and compiler version. There are too many cases.
156 word=`echo "$]$2[" | sed -e 's/word //' -e 's/ bit.*//'`
157 bit=`echo "$]$2[" | sed -e 's/word.*bit //'`
158 AC_DEFINE_UNQUOTED([$4][_SIGNBIT_WORD], [$word],
159 [Define as the word index where to find the sign of '$1'.])
160 AC_DEFINE_UNQUOTED([$4][_SIGNBIT_BIT], [$bit],
161 [Define as the bit index in the word where to find the sign of '$1'.])