Including <limits.h> in gmp-impl.h
Vincent Lefevre
vincent at vinc17.net
Fri Jan 3 03:19:57 UTC 2014
> --- 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)
Note that if you want to care of non-two's-complement
implementations, you should write:
#define __GMP_USHRT_MAX (0 + (unsigned short) -1)
I also find this code slightly more readable (since U..._MAX + 1 = 0
by definition, without having to think of the binary representation).
--
Vincent Lefèvre <vincent at vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the gmp-devel
mailing list