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
68 if test "$gl_cv_cc_float_signbit" = unknown; then
69 dnl Test whether copysignf() is declared.
70 AC_CHECK_DECLS([copysignf], , , [#include <math.h>])
71 if test "$ac_cv_have_decl_copysignf" = yes; then
72 dnl Test whether copysignf() can be used without libm.
73 AC_CACHE_CHECK([whether copysignf can be used without linking with libm],
74 [gl_cv_func_copysignf_no_libm],
76 AC_TRY_LINK([#include <math.h>
78 [return copysignf (x, y) < 0;],
79 [gl_cv_func_copysignf_no_libm=yes],
80 [gl_cv_func_copysignf_no_libm=no])
82 if test $gl_cv_func_copysignf_no_libm = yes; then
83 AC_DEFINE([HAVE_COPYSIGNF_IN_LIBC], 1,
84 [Define if the copysignf function is declared in <math.h> and available in libc.])
88 if test "$gl_cv_cc_double_signbit" = unknown; then
89 dnl Test whether copysign() is declared.
90 AC_CHECK_DECLS([copysign], , , [#include <math.h>])
91 if test "$ac_cv_have_decl_copysign" = yes; then
92 dnl Test whether copysign() can be used without libm.
93 AC_CACHE_CHECK([whether copysign can be used without linking with libm],
94 [gl_cv_func_copysign_no_libm],
96 AC_TRY_LINK([#include <math.h>
98 [return copysign (x, y) < 0;],
99 [gl_cv_func_copysign_no_libm=yes],
100 [gl_cv_func_copysign_no_libm=no])
102 if test $gl_cv_func_copysign_no_libm = yes; then
103 AC_DEFINE([HAVE_COPYSIGN_IN_LIBC], 1,
104 [Define if the copysign function is declared in <math.h> and available in libc.])
108 if test "$gl_cv_cc_long_double_signbit" = unknown; then
109 dnl Test whether copysignl() is declared.
110 AC_CHECK_DECLS([copysignl], , , [#include <math.h>])
111 if test "$ac_cv_have_decl_copysignl" = yes; then
112 dnl Test whether copysignl() can be used without libm.
113 AC_CACHE_CHECK([whether copysignl can be used without linking with libm],
114 [gl_cv_func_copysignl_no_libm],
116 AC_TRY_LINK([#include <math.h>
118 [return copysignl (x, y) < 0;],
119 [gl_cv_func_copysignl_no_libm=yes],
120 [gl_cv_func_copysignl_no_libm=no])
122 if test $gl_cv_func_copysignl_no_libm = yes; then
123 AC_DEFINE([HAVE_COPYSIGNL_IN_LIBC], 1,
124 [Define if the copysignl function is declared in <math.h> and available in libc.])
131 AC_DEFUN([gl_FLOAT_SIGN_LOCATION],
133 gl_FLOATTYPE_SIGN_LOCATION([float], [gl_cv_cc_float_signbit], [f], [FLT])
136 AC_DEFUN([gl_DOUBLE_SIGN_LOCATION],
138 gl_FLOATTYPE_SIGN_LOCATION([double], [gl_cv_cc_double_signbit], [], [DBL])
141 AC_DEFUN([gl_LONG_DOUBLE_SIGN_LOCATION],
143 gl_FLOATTYPE_SIGN_LOCATION([long double], [gl_cv_cc_long_double_signbit], [L], [LDBL])
146 AC_DEFUN([gl_FLOATTYPE_SIGN_LOCATION],
148 AC_CACHE_CHECK([where to find the sign bit in a '$1'],
155 ((sizeof ($1) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
156 typedef union { $1 value; unsigned int word[NWORDS]; }
158 static memory_float plus = { 1.0$3 };
159 static memory_float minus = { -1.0$3 };
164 FILE *fp = fopen ("conftest.out", "w");
167 /* Find the different bit. */
169 for (j = 0; j < NWORDS; j++)
171 unsigned int x = plus.word[j] ^ minus.word[j];
172 if ((x & (x - 1)) || (x && m))
174 /* More than one bit difference. */
175 fprintf (fp, "unknown");
187 fprintf (fp, "unknown");
190 /* Now m = plus.word[k] ^ ~minus.word[k]. */
191 if (plus.word[k] & ~minus.word[k])
193 /* Oh? The sign bit is set in the positive and cleared in the negative
195 fprintf (fp, "unknown");
201 fprintf (fp, "word %d bit %d", (int) k, (int) i);
202 return (fclose (fp) != 0);
205 [$2=`cat conftest.out`],
208 dnl When cross-compiling, we don't know. It depends on the
209 dnl ABI and compiler version. There are too many cases.
216 word=`echo "$]$2[" | sed -e 's/word //' -e 's/ bit.*//'`
217 bit=`echo "$]$2[" | sed -e 's/word.*bit //'`
218 AC_DEFINE_UNQUOTED([$4][_SIGNBIT_WORD], [$word],
219 [Define as the word index where to find the sign of '$1'.])
220 AC_DEFINE_UNQUOTED([$4][_SIGNBIT_BIT], [$bit],
221 [Define as the bit index in the word where to find the sign of '$1'.])