~ubuntu-branches/debian/experimental/lftp/experimental

« back to all changes in this revision

Viewing changes to m4/signbit.m4

  • Committer: Package Import Robot
  • Author(s): Noël Köthe
  • Date: 2015-08-21 16:06:22 UTC
  • mfrom: (1.1.20) (24.1.38 sid)
  • Revision ID: package-import@ubuntu.com-20150821160622-lckdmbiqx16wefgy
Tags: 4.6.4-1
new upstream release 2015-08-21

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# signbit.m4 serial 6
2
 
dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
 
1
# signbit.m4 serial 13
 
2
dnl Copyright (C) 2007-2015 Free Software Foundation, Inc.
3
3
dnl This file is free software; the Free Software Foundation
4
4
dnl gives unlimited permission to copy and/or distribute it,
5
5
dnl with or without modifications, as long as this notice is preserved.
7
7
AC_DEFUN([gl_SIGNBIT],
8
8
[
9
9
  AC_REQUIRE([gl_MATH_H_DEFAULTS])
 
10
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
10
11
  AC_CACHE_CHECK([for signbit macro], [gl_cv_func_signbit],
11
12
    [
12
 
      AC_TRY_RUN([
 
13
      AC_RUN_IFELSE(
 
14
        [AC_LANG_SOURCE([[
13
15
#include <math.h>
14
16
/* If signbit is defined as a function, don't use it, since calling it for
15
17
   'float' or 'long double' arguments would involve conversions.
23
25
#endif
24
26
#include <string.h>
25
27
]gl_SIGNBIT_TEST_PROGRAM
26
 
, [gl_cv_func_signbit=yes], [gl_cv_func_signbit=no],
27
 
        [gl_cv_func_signbit="guessing no"])
 
28
])],
 
29
        [gl_cv_func_signbit=yes],
 
30
        [gl_cv_func_signbit=no],
 
31
        [case "$host_os" in
 
32
                   # Guess yes on glibc systems.
 
33
           *-gnu*) gl_cv_func_signbit="guessing yes" ;;
 
34
                   # If we don't know, assume the worst.
 
35
           *)      gl_cv_func_signbit="guessing no" ;;
 
36
         esac
 
37
        ])
28
38
    ])
29
39
  dnl GCC 4.0 and newer provides three built-ins for signbit.
30
40
  dnl They can be used without warnings, also in C++, regardless of <math.h>.
32
42
  dnl libc.
33
43
  AC_CACHE_CHECK([for signbit compiler built-ins], [gl_cv_func_signbit_gcc],
34
44
    [
35
 
      AC_TRY_RUN([
 
45
      AC_RUN_IFELSE(
 
46
        [AC_LANG_SOURCE([[
36
47
#if __GNUC__ >= 4
37
48
# define signbit(x) \
38
49
   (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
43
54
#endif
44
55
#include <string.h>
45
56
]gl_SIGNBIT_TEST_PROGRAM
46
 
, [gl_cv_func_signbit_gcc=yes], [gl_cv_func_signbit_gcc=no],
47
 
        [gl_cv_func_signbit_gcc="guessing no"])
 
57
])],
 
58
        [gl_cv_func_signbit_gcc=yes],
 
59
        [gl_cv_func_signbit_gcc=no],
 
60
        [case "$host_os" in
 
61
                   # Guess yes on glibc systems.
 
62
           *-gnu*) gl_cv_func_signbit_gcc="guessing yes" ;;
 
63
                   # If we don't know, assume the worst.
 
64
           *)      gl_cv_func_signbit_gcc="guessing no" ;;
 
65
         esac
 
66
        ])
48
67
    ])
49
68
  dnl Use the compiler built-ins whenever possible, because they are more
50
69
  dnl efficient than the system library functions (if they exist).
51
 
  if test "$gl_cv_func_signbit_gcc" = yes; then
52
 
    REPLACE_SIGNBIT_USING_GCC=1
53
 
  else
54
 
    if test "$gl_cv_func_signbit" != yes; then
55
 
      REPLACE_SIGNBIT=1
56
 
      AC_LIBOBJ([signbitf])
57
 
      AC_LIBOBJ([signbitd])
58
 
      AC_LIBOBJ([signbitl])
59
 
      gl_FLOAT_SIGN_LOCATION
60
 
      gl_DOUBLE_SIGN_LOCATION
61
 
      gl_LONG_DOUBLE_SIGN_LOCATION
62
 
      if test "$gl_cv_cc_float_signbit" = unknown; then
63
 
        dnl Test whether copysignf() is declared.
64
 
        AC_CHECK_DECLS([copysignf], , , [#include <math.h>])
65
 
        if test "$ac_cv_have_decl_copysignf" = yes; then
66
 
          dnl Test whether copysignf() can be used without libm.
67
 
          AC_CACHE_CHECK([whether copysignf can be used without linking with libm],
68
 
            [gl_cv_func_copysignf_no_libm],
69
 
            [
70
 
              AC_TRY_LINK([#include <math.h>
71
 
                           float x, y;],
72
 
                          [return copysignf (x, y) < 0;],
73
 
                [gl_cv_func_copysignf_no_libm=yes],
74
 
                [gl_cv_func_copysignf_no_libm=no])
75
 
            ])
76
 
          if test $gl_cv_func_copysignf_no_libm = yes; then
77
 
            AC_DEFINE([HAVE_COPYSIGNF_IN_LIBC], [1],
78
 
              [Define if the copysignf function is declared in <math.h> and available in libc.])
79
 
          fi
80
 
        fi
81
 
      fi
82
 
      if test "$gl_cv_cc_double_signbit" = unknown; then
83
 
        dnl Test whether copysign() is declared.
84
 
        AC_CHECK_DECLS([copysign], , , [#include <math.h>])
85
 
        if test "$ac_cv_have_decl_copysign" = yes; then
86
 
          dnl Test whether copysign() can be used without libm.
87
 
          AC_CACHE_CHECK([whether copysign can be used without linking with libm],
88
 
            [gl_cv_func_copysign_no_libm],
89
 
            [
90
 
              AC_TRY_LINK([#include <math.h>
91
 
                           double x, y;],
92
 
                          [return copysign (x, y) < 0;],
93
 
                [gl_cv_func_copysign_no_libm=yes],
94
 
                [gl_cv_func_copysign_no_libm=no])
95
 
            ])
96
 
          if test $gl_cv_func_copysign_no_libm = yes; then
97
 
            AC_DEFINE([HAVE_COPYSIGN_IN_LIBC], [1],
98
 
              [Define if the copysign function is declared in <math.h> and available in libc.])
99
 
          fi
100
 
        fi
101
 
      fi
102
 
      if test "$gl_cv_cc_long_double_signbit" = unknown; then
103
 
        dnl Test whether copysignl() is declared.
104
 
        AC_CHECK_DECLS([copysignl], , , [#include <math.h>])
105
 
        if test "$ac_cv_have_decl_copysignl" = yes; then
106
 
          dnl Test whether copysignl() can be used without libm.
107
 
          AC_CACHE_CHECK([whether copysignl can be used without linking with libm],
108
 
            [gl_cv_func_copysignl_no_libm],
109
 
            [
110
 
              AC_TRY_LINK([#include <math.h>
111
 
                           long double x, y;],
112
 
                          [return copysignl (x, y) < 0;],
113
 
                [gl_cv_func_copysignl_no_libm=yes],
114
 
                [gl_cv_func_copysignl_no_libm=no])
115
 
            ])
116
 
          if test $gl_cv_func_copysignl_no_libm = yes; then
117
 
            AC_DEFINE([HAVE_COPYSIGNL_IN_LIBC], [1],
118
 
              [Define if the copysignl function is declared in <math.h> and available in libc.])
119
 
          fi
120
 
        fi
121
 
      fi
122
 
    fi
123
 
  fi
 
70
  case "$gl_cv_func_signbit_gcc" in
 
71
    *yes)
 
72
      REPLACE_SIGNBIT_USING_GCC=1
 
73
      ;;
 
74
    *)
 
75
      case "$gl_cv_func_signbit" in
 
76
        *yes) ;;
 
77
        *)
 
78
          dnl REPLACE_SIGNBIT=1 makes sure the signbit[fdl] functions get built.
 
79
          REPLACE_SIGNBIT=1
 
80
          gl_FLOAT_SIGN_LOCATION
 
81
          gl_DOUBLE_SIGN_LOCATION
 
82
          gl_LONG_DOUBLE_SIGN_LOCATION
 
83
          if test "$gl_cv_cc_float_signbit" = unknown; then
 
84
            dnl Test whether copysignf() is declared.
 
85
            AC_CHECK_DECLS([copysignf], , , [[#include <math.h>]])
 
86
            if test "$ac_cv_have_decl_copysignf" = yes; then
 
87
              dnl Test whether copysignf() can be used without libm.
 
88
              AC_CACHE_CHECK([whether copysignf can be used without linking with libm],
 
89
                [gl_cv_func_copysignf_no_libm],
 
90
                [
 
91
                  AC_LINK_IFELSE(
 
92
                    [AC_LANG_PROGRAM(
 
93
                       [[#include <math.h>
 
94
                         float x, y;]],
 
95
                       [[return copysignf (x, y) < 0;]])],
 
96
                    [gl_cv_func_copysignf_no_libm=yes],
 
97
                    [gl_cv_func_copysignf_no_libm=no])
 
98
                ])
 
99
              if test $gl_cv_func_copysignf_no_libm = yes; then
 
100
                AC_DEFINE([HAVE_COPYSIGNF_IN_LIBC], [1],
 
101
                  [Define if the copysignf function is declared in <math.h> and available in libc.])
 
102
              fi
 
103
            fi
 
104
          fi
 
105
          if test "$gl_cv_cc_double_signbit" = unknown; then
 
106
            dnl Test whether copysign() is declared.
 
107
            AC_CHECK_DECLS([copysign], , , [[#include <math.h>]])
 
108
            if test "$ac_cv_have_decl_copysign" = yes; then
 
109
              dnl Test whether copysign() can be used without libm.
 
110
              AC_CACHE_CHECK([whether copysign can be used without linking with libm],
 
111
                [gl_cv_func_copysign_no_libm],
 
112
                [
 
113
                  AC_LINK_IFELSE(
 
114
                    [AC_LANG_PROGRAM(
 
115
                       [[#include <math.h>
 
116
                         double x, y;]],
 
117
                       [[return copysign (x, y) < 0;]])],
 
118
                    [gl_cv_func_copysign_no_libm=yes],
 
119
                    [gl_cv_func_copysign_no_libm=no])
 
120
                ])
 
121
              if test $gl_cv_func_copysign_no_libm = yes; then
 
122
                AC_DEFINE([HAVE_COPYSIGN_IN_LIBC], [1],
 
123
                  [Define if the copysign function is declared in <math.h> and available in libc.])
 
124
              fi
 
125
            fi
 
126
          fi
 
127
          if test "$gl_cv_cc_long_double_signbit" = unknown; then
 
128
            dnl Test whether copysignl() is declared.
 
129
            AC_CHECK_DECLS([copysignl], , , [[#include <math.h>]])
 
130
            if test "$ac_cv_have_decl_copysignl" = yes; then
 
131
              dnl Test whether copysignl() can be used without libm.
 
132
              AC_CACHE_CHECK([whether copysignl can be used without linking with libm],
 
133
                [gl_cv_func_copysignl_no_libm],
 
134
                [
 
135
                  AC_LINK_IFELSE(
 
136
                    [AC_LANG_PROGRAM(
 
137
                       [[#include <math.h>
 
138
                         long double x, y;]],
 
139
                       [[return copysignl (x, y) < 0;]])],
 
140
                    [gl_cv_func_copysignl_no_libm=yes],
 
141
                    [gl_cv_func_copysignl_no_libm=no])
 
142
                ])
 
143
              if test $gl_cv_func_copysignl_no_libm = yes; then
 
144
                AC_DEFINE([HAVE_COPYSIGNL_IN_LIBC], [1],
 
145
                  [Define if the copysignl function is declared in <math.h> and available in libc.])
 
146
              fi
 
147
            fi
 
148
          fi
 
149
          ;;
 
150
      esac
 
151
      ;;
 
152
  esac
124
153
])
125
154
 
126
155
AC_DEFUN([gl_SIGNBIT_TEST_PROGRAM], [[
141
170
/* On HP-UX 10.20, negating 0.0L does not yield -0.0L.
142
171
   So we use another constant expression instead.
143
172
   But that expression does not work on other platforms, such as when
144
 
   cross-compiling to PowerPC on MacOS X 10.5.  */
 
173
   cross-compiling to PowerPC on Mac OS X 10.5.  */
145
174
long double p0l = 0.0L;
146
175
#if defined __hpux || defined __sgi
147
176
long double m0l = -LDBL_MIN * LDBL_MIN;
148
177
#else
149
178
long double m0l = -p0l;
150
179
#endif
151
 
  if (signbit (vf))
 
180
  int result = 0;
 
181
  if (signbit (vf)) /* link check */
152
182
    vf++;
153
183
  {
154
184
    float plus_inf = 1.0f / p0f;
159
189
          && (memcmp (&m0f, &p0f, sizeof (float)) == 0 || signbit (m0f))
160
190
          && !signbit (plus_inf)
161
191
          && signbit (minus_inf)))
162
 
      return 1;
 
192
      result |= 1;
163
193
  }
164
 
  if (signbit (vd))
 
194
  if (signbit (vd)) /* link check */
165
195
    vd++;
166
196
  {
167
197
    double plus_inf = 1.0 / p0d;
172
202
          && (memcmp (&m0d, &p0d, sizeof (double)) == 0 || signbit (m0d))
173
203
          && !signbit (plus_inf)
174
204
          && signbit (minus_inf)))
175
 
      return 1;
 
205
      result |= 2;
176
206
  }
177
 
  if (signbit (vl))
 
207
  if (signbit (vl)) /* link check */
178
208
    vl++;
179
209
  {
180
210
    long double plus_inf = 1.0L / p0l;
181
211
    long double minus_inf = -1.0L / p0l;
182
 
    if (!(!signbit (255.0L)
183
 
          && signbit (-255.0L)
184
 
          && !signbit (p0l)
185
 
          && (memcmp (&m0l, &p0l, sizeof (long double)) == 0 || signbit (m0l))
186
 
          && !signbit (plus_inf)
187
 
          && signbit (minus_inf)))
188
 
      return 1;
 
212
    if (signbit (255.0L))
 
213
      result |= 4;
 
214
    if (!signbit (-255.0L))
 
215
      result |= 4;
 
216
    if (signbit (p0l))
 
217
      result |= 8;
 
218
    if (!(memcmp (&m0l, &p0l, sizeof (long double)) == 0 || signbit (m0l)))
 
219
      result |= 16;
 
220
    if (signbit (plus_inf))
 
221
      result |= 32;
 
222
    if (!signbit (minus_inf))
 
223
      result |= 64;
189
224
  }
190
 
  return 0;
 
225
  return result;
191
226
}
192
227
]])
193
228
 
211
246
  AC_CACHE_CHECK([where to find the sign bit in a '$1'],
212
247
    [$2],
213
248
    [
214
 
      AC_TRY_RUN([
 
249
      AC_RUN_IFELSE(
 
250
        [AC_LANG_SOURCE([[
215
251
#include <stddef.h>
216
252
#include <stdio.h>
217
253
#define NWORDS \
236
272
        {
237
273
          /* More than one bit difference.  */
238
274
          fprintf (fp, "unknown");
239
 
          return 1;
 
275
          return 2;
240
276
        }
241
277
      if (x)
242
278
        {
248
284
    {
249
285
      /* No difference.  */
250
286
      fprintf (fp, "unknown");
251
 
      return 1;
 
287
      return 3;
252
288
    }
253
289
  /* Now m = plus.word[k] ^ ~minus.word[k].  */
254
290
  if (plus.word[k] & ~minus.word[k])
256
292
      /* Oh? The sign bit is set in the positive and cleared in the negative
257
293
         numbers?  */
258
294
      fprintf (fp, "unknown");
259
 
      return 1;
 
295
      return 4;
260
296
    }
261
297
  for (i = 0; ; i++)
262
298
    if ((m >> i) & 1)
263
299
      break;
264
300
  fprintf (fp, "word %d bit %d", (int) k, (int) i);
265
 
  return (fclose (fp) != 0);
 
301
  if (fclose (fp) != 0)
 
302
    return 5;
 
303
  return 0;
266
304
}
267
 
        ],
 
305
        ]])],
268
306
        [$2=`cat conftest.out`],
269
307
        [$2="unknown"],
270
308
        [
285
323
      ;;
286
324
  esac
287
325
])
 
326
 
 
327
# Expands to code that defines a function signbitf(float).
 
328
# It extracts the sign bit of a non-NaN value.
 
329
AC_DEFUN([gl_FLOAT_SIGNBIT_CODE],
 
330
[
 
331
  gl_FLOATTYPE_SIGNBIT_CODE([float], [f], [f])
 
332
])
 
333
 
 
334
# Expands to code that defines a function signbitd(double).
 
335
# It extracts the sign bit of a non-NaN value.
 
336
AC_DEFUN([gl_DOUBLE_SIGNBIT_CODE],
 
337
[
 
338
  gl_FLOATTYPE_SIGNBIT_CODE([double], [d], [])
 
339
])
 
340
 
 
341
# Expands to code that defines a function signbitl(long double).
 
342
# It extracts the sign bit of a non-NaN value.
 
343
AC_DEFUN([gl_LONG_DOUBLE_SIGNBIT_CODE],
 
344
[
 
345
  gl_FLOATTYPE_SIGNBIT_CODE([long double], [l], [L])
 
346
])
 
347
 
 
348
AC_DEFUN([gl_FLOATTYPE_SIGNBIT_CODE],
 
349
[[
 
350
static int
 
351
signbit$2 ($1 value)
 
352
{
 
353
  typedef union { $1 f; unsigned char b[sizeof ($1)]; } float_union;
 
354
  static float_union plus_one = { 1.0$3 };   /* unused bits are zero here */
 
355
  static float_union minus_one = { -1.0$3 }; /* unused bits are zero here */
 
356
  /* Compute the sign bit mask as the XOR of plus_one and minus_one.  */
 
357
  float_union u;
 
358
  unsigned int i;
 
359
  u.f = value;
 
360
  for (i = 0; i < sizeof ($1); i++)
 
361
    if (u.b[i] & (plus_one.b[i] ^ minus_one.b[i]))
 
362
      return 1;
 
363
  return 0;
 
364
}
 
365
]])