diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2014-01-02 13:25:31 +0100 |
---|---|---|
committer | Marc Glisse <marc.glisse@inria.fr> | 2014-01-02 13:25:31 +0100 |
commit | 5e05d1f7516879559f504bf267cd84235ff24655 (patch) | |
tree | b5cdbcd800bff6ac476941e304fff2e8e1e916a7 | |
parent | b892dcad77d5d15b5f79e764802d33206efbc710 (diff) | |
download | gmp-5e05d1f7516879559f504bf267cd84235ff24655.tar.gz |
SHRT_MAX etc have the promoted type in standard C.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | gmp-h.in | 4 | ||||
-rw-r--r-- | gmp-impl.h | 6 | ||||
-rw-r--r-- | tests/t-constants.c | 8 | ||||
-rw-r--r-- | tests/t-gmpmax.c | 10 |
5 files changed, 17 insertions, 16 deletions
@@ -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@gmplib.org> * doc/gmp.texi (Low-level Functions for cryptography): Update interface @@ -437,10 +437,10 @@ typedef __mpq_struct *mpq_ptr; #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 --git a/gmp-impl.h b/gmp-impl.h index a695c3cee..2811d6b7e 100644 --- a/gmp-impl.h +++ b/gmp-impl.h @@ -562,7 +562,7 @@ __GMP_DECLSPEC void __gmp_tmp_debug_free (const char *, int, int, 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 @@ __GMP_DECLSPEC void __gmp_tmp_debug_free (const char *, int, int, #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 --git a/tests/t-constants.c b/tests/t-constants.c index 2dd745ed1..2f69e8153 100644 --- a/tests/t-constants.c +++ b/tests/t-constants.c @@ -329,10 +329,10 @@ main (int argc, char *argv[]) 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 --git a/tests/t-gmpmax.c b/tests/t-gmpmax.c index 772548b94..76fdd28e6 100644 --- a/tests/t-gmpmax.c +++ b/tests/t-gmpmax.c @@ -42,12 +42,8 @@ main (int argc, char *argv[]) } #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 @@ main (int argc, char *argv[]) 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 |