[Gmp-commit] /var/hg/gmp: Include and rely on <limits.h>.
mercurial at gmplib.org
mercurial at gmplib.org
Thu May 29 12:27:20 UTC 2014
details: /var/hg/gmp/rev/902a1b8de2e0
changeset: 16402:902a1b8de2e0
user: Marc Glisse <marc.glisse at inria.fr>
date: Thu May 29 14:25:22 2014 +0200
description:
Include and rely on <limits.h>.
diffstat:
ChangeLog | 9 +++++++
gmp-h.in | 17 ++++--------
gmp-impl.h | 39 -------------------------------
tests/Makefile.am | 2 +-
tests/t-gmpmax.c | 69 -------------------------------------------------------
5 files changed, 16 insertions(+), 120 deletions(-)
diffs (225 lines):
diff -r 79920e0e021a -r 902a1b8de2e0 ChangeLog
--- a/ChangeLog Thu May 22 09:05:26 2014 +0200
+++ b/ChangeLog Thu May 29 14:25:22 2014 +0200
@@ -1,3 +1,12 @@
+2014-05-29 Marc Glisse <marc.glisse at inria.fr>
+
+ * gmp-h.in: Include <limits.h>.
+ (__GMP_UINT_MAX, __GMP_ULONG_MAX, __GMP_USHRT_MAX): Remove.
+ * gmp-impl.h (ULONG_MAX, UINT_MAX, USHRT_MAX, LONG_MAX, INT_MAX,
+ SHRT_MAX): Remove unnecessary redefinition.
+ * tests/t-gmpmax.c: Remove file.
+ * tests/Makefile.am: Remove t-gmpmax.
+
2014-05-22 Marco Bodrato <bodrato at mail.dm.unipi.it>
* tests/mpf/t-sub.c (check_data): Test also ui_sub and sub_ui.
diff -r 79920e0e021a -r 902a1b8de2e0 gmp-h.in
--- a/gmp-h.in Thu May 22 09:05:26 2014 +0200
+++ b/gmp-h.in Thu May 29 14:25:22 2014 +0200
@@ -56,6 +56,7 @@
#define __GNU_MP__ 5
#include <stddef.h> /* for size_t */
+#include <limits.h>
/* Instantiated by configure. */
#if ! defined (__GMP_WITHIN_CONFIGURE)
@@ -445,12 +446,6 @@
#define __GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
#define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i))
-/* __GMP_USHRT_MAX is not "~ (unsigned short) 0" because short is promoted
- to int by "~". It still needs to have the promoted type. */
-#define __GMP_UINT_MAX (~ (unsigned) 0)
-#define __GMP_ULONG_MAX (~ (unsigned long) 0)
-#define __GMP_USHRT_MAX (0 + (unsigned short) ~0)
-
/* __builtin_expect is in gcc 3.0, and not in 2.95. */
#if __GMP_GNUC_PREREQ (3,0)
@@ -1727,7 +1722,7 @@
int
mpz_fits_uint_p (mpz_srcptr __gmp_z) __GMP_NOTHROW
{
- __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_UINT_MAX);
+ __GMPZ_FITS_UTYPE_P (__gmp_z, UINT_MAX);
}
#endif
@@ -1738,7 +1733,7 @@
int
mpz_fits_ulong_p (mpz_srcptr __gmp_z) __GMP_NOTHROW
{
- __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_ULONG_MAX);
+ __GMPZ_FITS_UTYPE_P (__gmp_z, ULONG_MAX);
}
#endif
@@ -1749,7 +1744,7 @@
int
mpz_fits_ushort_p (mpz_srcptr __gmp_z) __GMP_NOTHROW
{
- __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_USHRT_MAX);
+ __GMPZ_FITS_UTYPE_P (__gmp_z, USHRT_MAX);
}
#endif
@@ -1766,7 +1761,7 @@
/* This is a "#if" rather than a plain "if" so as to avoid gcc warnings
about "<< GMP_NUMB_BITS" exceeding the type size, and to avoid Borland
C++ 6.0 warnings about condition always true for something like
- "__GMP_ULONG_MAX < GMP_NUMB_MASK". */
+ "ULONG_MAX < GMP_NUMB_MASK". */
#if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB)
/* limb==long and no nails, or limb==longlong, one limb is enough */
return (__gmp_n != 0 ? __gmp_l : 0);
@@ -1834,7 +1829,7 @@
mp_bitcnt_t __gmp_result;
__gmp_usize = __gmp_u->_mp_size;
- __gmp_result = (__gmp_usize < 0 ? __GMP_ULONG_MAX : 0);
+ __gmp_result = (__gmp_usize < 0 ? ULONG_MAX : 0);
if (__GMP_LIKELY (__gmp_usize > 0))
__gmp_result = mpn_popcount (__gmp_u->_mp_d, __gmp_usize);
return __gmp_result;
diff -r 79920e0e021a -r 902a1b8de2e0 gmp-impl.h
--- a/gmp-impl.h Thu May 22 09:05:26 2014 +0200
+++ b/gmp-impl.h Thu May 29 14:25:22 2014 +0200
@@ -547,24 +547,6 @@
((n) >= 0x100) + ((n) >= 0x200) + ((n) >= 0x400) + ((n) >= 0x800) + \
((n) >= 0x1000) + ((n) >= 0x2000) + ((n) >= 0x4000) + ((n) >= 0x8000))
-/* The "short" defines are a bit different because shorts are promoted to
- ints by ~ or >> etc.
-
- #ifndef's are used since on some systems (HP?) header files other than
- limits.h setup these defines. We could forcibly #undef in that case, but
- there seems no need to worry about that.
-
- Now that we include <limits.h> we should be able to remove all this. */
-
-#ifndef ULONG_MAX
-#define ULONG_MAX __GMP_ULONG_MAX
-#endif
-#ifndef UINT_MAX
-#define UINT_MAX __GMP_UINT_MAX
-#endif
-#ifndef USHRT_MAX
-#define USHRT_MAX __GMP_USHRT_MAX
-#endif
#define MP_LIMB_T_MAX (~ (mp_limb_t) 0)
/* Must cast ULONG_MAX etc to unsigned long etc, since they might not be
@@ -575,27 +557,6 @@
#define USHRT_HIGHBIT (USHRT_MAX ^ ((unsigned short) USHRT_MAX >> 1))
#define GMP_LIMB_HIGHBIT (MP_LIMB_T_MAX ^ (MP_LIMB_T_MAX >> 1))
-#ifndef LONG_MIN
-#define LONG_MIN ((long) ULONG_HIGHBIT)
-#endif
-#ifndef LONG_MAX
-#define LONG_MAX (-(LONG_MIN+1))
-#endif
-
-#ifndef INT_MIN
-#define INT_MIN ((int) UINT_HIGHBIT)
-#endif
-#ifndef INT_MAX
-#define INT_MAX (-(INT_MIN+1))
-#endif
-
-#ifndef SHRT_MIN
-#define SHRT_MIN ((int) (short) USHRT_HIGHBIT)
-#endif
-#ifndef SHRT_MAX
-#define SHRT_MAX (-(SHRT_MIN+1))
-#endif
-
#if __GMP_MP_SIZE_T_INT
#define MP_SIZE_T_MAX INT_MAX
#define MP_SIZE_T_MIN INT_MIN
diff -r 79920e0e021a -r 902a1b8de2e0 tests/Makefile.am
--- a/tests/Makefile.am Thu May 22 09:05:26 2014 +0200
+++ b/tests/Makefile.am Thu May 29 14:25:22 2014 +0200
@@ -34,6 +34,6 @@
libtests_la_DEPENDENCIES = @CALLING_CONVENTIONS_OBJS@
libtests_la_LIBADD = $(libtests_la_DEPENDENCIES) $(top_builddir)/libgmp.la
-check_PROGRAMS = t-bswap t-constants t-count_zeros t-gmpmax t-hightomask \
+check_PROGRAMS = t-bswap t-constants t-count_zeros t-hightomask \
t-modlinv t-popc t-parity t-sub
TESTS = $(check_PROGRAMS)
diff -r 79920e0e021a -r 902a1b8de2e0 tests/t-gmpmax.c
--- a/tests/t-gmpmax.c Thu May 22 09:05:26 2014 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/* Check the values of __GMP_UINT_MAX etc.
-
-Copyright 2001 Free Software Foundation, Inc.
-
-This file is part of the GNU MP Library test suite.
-
-The GNU MP Library test suite is free software; you can redistribute it
-and/or modify it under the terms of the GNU General Public License as
-published by the Free Software Foundation; either version 3 of the License,
-or (at your option) any later version.
-
-The GNU MP Library test suite is distributed in the hope that it will be
-useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
-Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include "gmp.h"
-
-
-/* __GMP_UINT_MAX etc are generated with expressions in gmp.h since we don't
- want to demand <limits.h> or forcibly include it. Check the expressions
- come out the same as <limits.h>. */
-
-int
-main (int argc, char *argv[])
-{
- int error = 0;
-
-#ifdef UINT_MAX
- if (__GMP_UINT_MAX != UINT_MAX)
- {
- printf ("__GMP_UINT_MAX incorrect\n");
- printf (" __GMP_UINT_MAX %u 0x%X\n", __GMP_UINT_MAX, __GMP_UINT_MAX);
- printf (" UINT_MAX %u 0x%X\n", UINT_MAX, UINT_MAX);
- error = 1;
- }
-#endif
-
-#ifdef ULONG_MAX
- if (__GMP_ULONG_MAX != ULONG_MAX)
- {
- printf ("__GMP_ULONG_MAX incorrect\n");
- printf (" __GMP_ULONG_MAX %lu 0x%lX\n", __GMP_ULONG_MAX, __GMP_ULONG_MAX);
- printf (" ULONG_MAX %lu 0x%lX\n", ULONG_MAX, ULONG_MAX);
- error = 1;
- }
-#endif
-
-#ifdef USHRT_MAX
- if (__GMP_USHRT_MAX != USHRT_MAX)
- {
- printf ("__GMP_USHRT_MAX incorrect\n");
- printf (" __GMP_USHRT_MAX %u 0x%X\n", __GMP_USHRT_MAX, __GMP_USHRT_MAX);
- printf (" USHRT_MAX %u 0x%X\n", USHRT_MAX, USHRT_MAX);
- error = 1;
- }
-#endif
-
- if (error)
- abort ();
-
- exit (0);
-}
More information about the gmp-commit
mailing list