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: Wed, 28 Dec 2005 11:17:41 -0500
User-agent: Mutt/1.4.1i

On Wed, Dec 28, 2005 at 10:37:16AM -0500, Andrew J. Schorr wrote:
> Oops, the last patch used the isfinite() function, but that should
> probably be avoided, since it doesn't seem to be present on some
> platforms (e.g. it's not in Solaris 8).  Revised patch attached.

I'm afraid replacing the isfinite(x) test with (x+1 > x) had some unintended
side effects: it now declares 2^64 to be out of range for "%d" formatting.
That makes a certain amount of sense (since it has exceeded the integer
resolution of the floating point type), but may not be desirable, depending on
your opinion of how "%d" should behave for values that are beyond the integer
range of the AWKNUM type.  Is there some other simple test that will catch only
NaN and Inf?

So with the last patch I sent (on linux-x86 32 bits):

$ ./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 `%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
-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 `%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

$ ./gawk --lint 'BEGIN {x = sqrt(-1); printf "x = %s %g %d %x\n",x,x,x,x}'
gawk: warning: sqrt: called with negative argument -1
gawk: warning: [s]printf: value nan is out of range for `%d' format
gawk: warning: [s]printf: value nan is out of range for `%x' format
x = nan nan nan nan

$ ./gawk --lint 'BEGIN {x = log(0); printf "x = %s %g %d %x\n",x,x,x,x}'
gawk: warning: [s]printf: value -inf is out of range for `%d' format
gawk: warning: [s]printf: value -inf is out of range for `%x' format
x = -inf -inf -inf -inf

Regards,
Andy




reply via email to

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