[Top][All Lists]

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

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

From: Paul Eggert
Subject: Re: [bug-grep] Re: length of dec. representation of a number
Date: Thu, 10 Mar 2005 17:14:49 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Stepan Kasal <address@hidden> writes:

> /* True if the arithmetic type T is signed.  */
> #define TYPE_SIGNED(t) ((t) 1 > (t) -1)

The existing macro has been tested with weird Cray compilers and the
like.  It's written weirdly because they have strange bugs.  I'd
rather not tempt fate by changing it.

> /* Note that we cannot use (1 << ...) on the last line, because << can
>    act as sign-preserving shift.  (In theory, << is undefined as soon as
>    the leftmost bit of the left operand is set, no matter whether the
>    type is signed or not, but in practice this code works.)  */

This comment is a bit controversial.  Not everyone agrees that the
behavior is undefined.  As far as I know the C committee hasn't ruled
on the subject.  I'd rather omit the discussion.

> #define INT_STRLEN_BOUND(t) \
>   ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 146 / 485 + 1 \
>       + TYPE_SIGNED (t))

Offhand I'd rather leave it the way that it is, so that the macro
works on objects as well as on types.  (If we ever run into the
situation where it's important to save 1 byte for printable
representations of 128-bit unsigned integers, we can revisit this

reply via email to

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