[Gmp-commit] /var/hg/gmp: SHRT_MAX etc have the promoted type in standard C.
mercurial at gmplib.org
mercurial at gmplib.org
Thu Jan 2 12:27:52 UTC 2014
details: /var/hg/gmp/rev/523511a9e8ee
changeset: 16148:523511a9e8ee
user: Marc Glisse <marc.glisse at inria.fr>
date: Thu Jan 02 13:25:31 2014 +0100
description:
SHRT_MAX etc have the promoted type in standard C.
diffstat:
ChangeLog | 5 +++++
gmp-h.in | 4 ++--
gmp-impl.h | 6 +++---
tests/t-constants.c | 8 ++++----
tests/t-gmpmax.c | 10 +++-------
5 files changed, 17 insertions(+), 16 deletions(-)
diffs (102 lines):
diff -r 75c45ba987ab -r 523511a9e8ee ChangeLog
--- a/ChangeLog Thu Jan 02 12:28:21 2014 +0100
+++ b/ChangeLog Thu Jan 02 13:25:31 2014 +0100
@@ -3,6 +3,11 @@
* gmp-impl.h: Always include <limits.h>.
* tests/mpn/t-get_d.c: Remove comment about <limits.h>
+ * gmp-h.in (__GMP_USHRT_MAX): Use the promoted type.
+ * gmp-impl.h (USHRT_HIGHBIT, SHRT_MIN, SHRT_MAX): Likewise.
+ * tests/t-constants.c: Adapt printf strings.
+ * tests/t-gmpmax.c: Likewise.
+
2014-01-01 Torbjorn Granlund <tege at gmplib.org>
* doc/gmp.texi (Low-level Functions for cryptography): Update interface
diff -r 75c45ba987ab -r 523511a9e8ee gmp-h.in
--- a/gmp-h.in Thu Jan 02 12:28:21 2014 +0100
+++ b/gmp-h.in Thu Jan 02 13:25:31 2014 +0100
@@ -437,10 +437,10 @@
#define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i))
/* __GMP_USHRT_MAX is not "~ (unsigned short) 0" because short is promoted
- to int by "~". */
+ 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 ((unsigned short) ~0)
+#define __GMP_USHRT_MAX (0 + (unsigned short) ~0)
/* __builtin_expect is in gcc 3.0, and not in 2.95. */
diff -r 75c45ba987ab -r 523511a9e8ee gmp-impl.h
--- a/gmp-impl.h Thu Jan 02 12:28:21 2014 +0100
+++ b/gmp-impl.h Thu Jan 02 13:25:31 2014 +0100
@@ -562,7 +562,7 @@
treats the plain decimal values in <limits.h> as signed. */
#define ULONG_HIGHBIT (ULONG_MAX ^ ((unsigned long) ULONG_MAX >> 1))
#define UINT_HIGHBIT (UINT_MAX ^ ((unsigned) UINT_MAX >> 1))
-#define USHRT_HIGHBIT ((unsigned short) (USHRT_MAX ^ ((unsigned short) USHRT_MAX >> 1)))
+#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
@@ -580,10 +580,10 @@
#endif
#ifndef SHRT_MIN
-#define SHRT_MIN ((short) USHRT_HIGHBIT)
+#define SHRT_MIN ((int) (short) USHRT_HIGHBIT)
#endif
#ifndef SHRT_MAX
-#define SHRT_MAX ((short) (-(SHRT_MIN+1)))
+#define SHRT_MAX (-(SHRT_MIN+1))
#endif
#if __GMP_MP_SIZE_T_INT
diff -r 75c45ba987ab -r 523511a9e8ee tests/t-constants.c
--- a/tests/t-constants.c Thu Jan 02 12:28:21 2014 +0100
+++ b/tests/t-constants.c Thu Jan 02 13:25:31 2014 +0100
@@ -329,10 +329,10 @@
printf ("INT_MAX %X\n", INT_MAX);
printf ("INT_MIN %X\n", INT_MIN);
- printf ("USHRT_MAX %hX\n", USHRT_MAX);
- printf ("USHRT_HIGHBIT %hX\n", USHRT_HIGHBIT);
- printf ("SHRT_MAX %hX\n", SHRT_MAX);
- printf ("SHRT_MIN %hX\n", SHRT_MIN);
+ printf ("USHRT_MAX %X\n", USHRT_MAX);
+ printf ("USHRT_HIGHBIT %X\n", USHRT_HIGHBIT);
+ printf ("SHRT_MAX %X\n", SHRT_MAX);
+ printf ("SHRT_MIN %X\n", SHRT_MIN);
printf ("\n");
printf ("Bits\n");
diff -r 75c45ba987ab -r 523511a9e8ee tests/t-gmpmax.c
--- a/tests/t-gmpmax.c Thu Jan 02 12:28:21 2014 +0100
+++ b/tests/t-gmpmax.c Thu Jan 02 13:25:31 2014 +0100
@@ -42,12 +42,8 @@
}
#endif
- /* gcc 2.95.2 limits.h on solaris 2.5.1 incorrectly selects a 64-bit
- LONG_MAX, leading to some integer overflow in ULONG_MAX and a spurious
- __GMP_ULONG_MAX != ULONG_MAX. Casting ULONG_MAX to unsigned long is a
- workaround. */
#ifdef ULONG_MAX
- if (__GMP_ULONG_MAX != (unsigned long) 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);
@@ -60,8 +56,8 @@
if (__GMP_USHRT_MAX != USHRT_MAX)
{
printf ("__GMP_USHRT_MAX incorrect\n");
- printf (" __GMP_USHRT_MAX %hu 0x%hX\n", __GMP_USHRT_MAX, __GMP_USHRT_MAX);
- printf (" USHRT_MAX %hu 0x%hX\n", USHRT_MAX, USHRT_MAX);
+ 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
More information about the gmp-commit
mailing list