Including <limits.h> in gmp-impl.h

Vincent Lefevre vincent at vinc17.net
Fri Jan 3 12:36:43 UTC 2014


On 2014-01-03 12:19:26 +0100, Marc Glisse wrote:
> On Fri, 3 Jan 2014, Torbjorn Granlund wrote:
> 
> >Vincent Lefevre <vincent at vinc17.net> writes:
> >
> > Note that if you want to care of non-two's-complement
> > implementations, you should write:
> 
> Isn't the notion of 2's complement restricted to signed types?

Yes, but in ~0, 0 is of signed type. In non-two's-complement
implementations, 0 may have several representations, so that
~0 is not guaranteed to work.

> > #define __GMP_USHRT_MAX  (0 + (unsigned short) -1)
> 
> The previous form has worked so far, and I'd like to remove the macro
> completely soon, so it doesn't seem worth it.
> 
> >Is that out-of-range conversion really Proper C?
> 
> unsigned = modular arithmetic, so yes, it is fine.

Anyway if -1 didn't work, then ~0 wouldn't have worked either,
because the result of ~0 is -1. Not to be confused with ~0U or
~ (unsigned int) 0.

-- 
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