Re: [bug-grep] Re: length of dec. representation of a number
[EMAIL PROTECTED] (Paul Jarc) wrote: Paul Eggert [EMAIL PROTECTED] wrote: /* Bound on length of the string representing an integer value or type T. Subtract 1 for the sign bit if t is signed; log10 (2.0) 146/485; add 1 for integer division truncation; add 1 more for a minus sign if needed. */ #define INT_STRLEN_BOUND(t) \ ((sizeof (t) * CHAR_BIT - 1) * 146 / 485 + 2) I guess that should be: #define INT_STRLEN_BOUND(t) \ ((sizeof (t) * CHAR_BIT - TYPE_SIGNED(t)) * 146 / 485 + TYPE_SIGNED(t) + 1) Technically, yes, but that would prohibit applying that macro to variables, which is useful. Currently there are uses like that in the coreutils. ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: [bug-grep] Re: length of dec. representation of a number
Jim Meyering [EMAIL PROTECTED] wrote: Technically, yes, but that would prohibit applying that macro to variables, which is useful. Currently there are uses like that in the coreutils. Ah - well, it's easy enough to factor, so you'd have to specify the signedness explicitly for variables, but it would be automatically detected for types. #define INT_STRLEN_BOUND_VAR(t, signedness) ... #define INT_STRLEN_BOUND_TYPE(t) INT_STRLEN_BOUND_VAR(t, TYPE_SIGNED(t)) paul ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: [bug-grep] Re: length of dec. representation of a number
[EMAIL PROTECTED] (Paul Jarc) wrote: Jim Meyering [EMAIL PROTECTED] wrote: Technically, yes, but that would prohibit applying that macro to variables, which is useful. Currently there are uses like that in the coreutils. Ah - well, it's easy enough to factor, so you'd have to specify the signedness explicitly for variables, but it would be automatically detected for types. #define INT_STRLEN_BOUND_VAR(t, signedness) ... #define INT_STRLEN_BOUND_TYPE(t) INT_STRLEN_BOUND_VAR(t, TYPE_SIGNED(t)) I don't see the benefit. Having to specify signedness makes it unmaintainable. It'd be too easy to get wrong, or (more likely) to render incorrect with a subsequent variable type change. ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils