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: Andrew J. Schorr
Subject: Re: gawk number to string bug
Date: Tue, 27 Dec 2005 17:01:19 -0500
User-agent: Mutt/1.4.1i

On Mon, Dec 26, 2005 at 10:11:52AM -0800, Paul Eggert wrote:
> (1) Fix the buffer overruns.
> (2) Fix the rounding errors.
> (3) Use %.0f to to handle %d for out-of-range integers.

That could certainly make sense.  I defer to Arnold on that issue.

> Anyway, here are the problems I had with the patch you sent:
> 
> $ patch -p0 <$j/t
...
> patching file builtin.c
> Hunk #5 FAILED at 966.
> Hunk #6 FAILED at 1002.
> Hunk #8 FAILED at 1108.

OK, I have attached a version that should apply cleanly against gawk 3.1.5.
And I improved the patch a bit.

On linux-x86 32 bits, with stock gawk 3.1.5:

$ ./gawk --lint 'BEGIN { x=2^60; for(i=60;i<=65;i++) { printf "2^%d= %s %d %g 
%x\n",i,x,x,x,x; x*=2} x=-2^60; for(i=60;i<=65;i++) { printf "-2^%d= %s %d %g 
%x\n",i,x,x,x,x; x*=2}}'
2^60= 1.15292e+18 1152921504606846976 1.15292e+18 1000000000000000
2^61= 2.30584e+18 2305843009213693952 2.30584e+18 2000000000000000
2^62= 4.61169e+18 4611686018427387904 4.61169e+18 4000000000000000
2^63= 9.22337e+18 9223372036854775808 9.22337e+18 8000000000000000
2^64= 1.84467e+19 0 1.84467e+19 0
gawk: warning: [s]printf: value 3.68935e+19 is out of range for `%d' format
gawk: warning: [s]printf: value 3.68935e+19 is out of range for `%x' format
2^65= 3.68935e+19 3.68935e+19 3.68935e+19 3.68935e+19
-2^60= -1.15292e+18 -1152921504606846976 -1.15292e+18 f000000000000000
-2^61= -2.30584e+18 -2305843009213693952 -2.30584e+18 e000000000000000
-2^62= -4.61169e+18 -4611686018427387904 -4.61169e+18 c000000000000000
-2^63= -9.22337e+18 -9223372036854775808 -9.22337e+18 8000000000000000
gawk: warning: [s]printf: value -1.84467e+19 is out of range for `%d' format
gawk: warning: [s]printf: value -1.84467e+19 is out of range for `%x' format
-2^64= -1.84467e+19 -1.84467e+19 -1.84467e+19 -1.84467e+19
gawk: warning: [s]printf: value -3.68935e+19 is out of range for `%d' format
gawk: warning: [s]printf: value -3.68935e+19 is out of range for `%x' format
-2^65= -3.68935e+19 -3.68935e+19 -3.68935e+19 -3.68935e+19


And with the patched version:

$ ./gawk --lint 'BEGIN { x=2^60; for(i=60;i<=65;i++) { printf "2^%d= %s %d %g 
%x\n",i,x,x,x,x; x*=2} x=-2^60; for(i=60;i<=65;i++) { printf "-2^%d= %s %d %g 
%x\n",i,x,x,x,x; x*=2}}'
2^60= 1.15292e+18 1152921504606846976 1.15292e+18 1000000000000000
2^61= 2.30584e+18 2305843009213693952 2.30584e+18 2000000000000000
2^62= 4.61169e+18 4611686018427387904 4.61169e+18 4000000000000000
2^63= 9.22337e+18 9223372036854775808 9.22337e+18 8000000000000000
gawk: warning: [s]printf: value 1.84467e+19 is out of range for `%x' format
2^64= 1.84467e+19 18446744073709551616 1.84467e+19 1.84467e+19
gawk: warning: [s]printf: value 3.68935e+19 is out of range for `%x' format
2^65= 3.68935e+19 36893488147419103232 3.68935e+19 3.68935e+19
-2^60= -1.15292e+18 -1152921504606846976 -1.15292e+18 f000000000000000
-2^61= -2.30584e+18 -2305843009213693952 -2.30584e+18 e000000000000000
-2^62= -4.61169e+18 -4611686018427387904 -4.61169e+18 c000000000000000
-2^63= -9.22337e+18 -9223372036854775808 -9.22337e+18 8000000000000000
gawk: warning: [s]printf: value -1.84467e+19 is out of range for `%x' format
-2^64= -1.84467e+19 -18446744073709551616 -1.84467e+19 -1.84467e+19
gawk: warning: [s]printf: value -3.68935e+19 is out of range for `%x' format
-2^65= -3.68935e+19 -36893488147419103232 -3.68935e+19 -3.68935e+19

Regards,
Andy

Attachment: gawk315.patch
Description: Text document


reply via email to

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