bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: gawk number to string bug


From: Paul Eggert
Subject: Re: gawk number to string bug
Date: Sun, 25 Dec 2005 11:39:48 -0800
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

"Andrew J. Schorr" <address@hidden> writes:

> refers to the situation where a numeric (integer) value is being
> converted to a string (perhaps by print, printf "%s", or by context).

Yes, that's right.  This is the part of the spec that I referred to in
<http://lists.gnu.org/archive/html/bug-gnu-utils/2005-12/msg00117.html>.

> Anyway, I still do not see anything that addresses how to format
> a numeric value with "%d" when the numeric value overflows the
> standard integer type.

That is covered later on in
<http://www.opengroup.org/onlinepubs/000095399/utilities/awk.html>,
under the paragraph starting with "The printf statement".  It says:

   8. For each conversion specification that consumes an argument, the
   next expression argument shall be evaluated. With the exception of
   the c conversion specifier character, the value shall be converted
   (according to the rules specified in Expressions in awk) to the
   appropriate type for the conversion specification.

Here, the appropriate type is integer, and the behavior is undefined
if the numeric value is not an integer (i.e., doesn't fit in a finite
range that is at least that of a 32-bit signed integer).  Hence, if
the value is out of range, POSIX allows gawk to use "%.0f".  However,
if the value is in range, "%.0f" should not be used if it produces
results differing from "%d" (which can occur with -0.0, for example).

I was also worried about flag characters, e.g., the "0" in "%01d", but
I guess if we use %.0f only for not-in-range values we should be OK.




reply via email to

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