[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-grep] length of dec. representation of a number

From: Jim Meyering
Subject: Re: [bug-grep] length of dec. representation of a number
Date: Tue, 08 Mar 2005 18:59:16 +0100

address@hidden (Paul Jarc) wrote:
> Jim Meyering <address@hidden> wrote:
>> Another such header file might include definitions for TYPE_MINIMUM and
> For unsigned types, they're trivial, and for signed types, I don't
> it's possible to calculate them unless you either invoke
> unspecified/undefined behavior, or make assumptions about padding bits
> and 2's-complement/1's-complement/sign+magnitude representation.

Here are the ones that have been in coreutils/src/system.h, gnulib,
and other packages for a long time.  If you know of a system that's
actually in use but for which they don't work, please let us know.

/* The extra casts work around common compiler bugs.  */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
/* The outer cast is needed to work around a bug in Cray C
   It is necessary at least when t == time_t.  */
#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
                              ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
#define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]