bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Overflow to Infinity


From: Daniel Pettet
Subject: Re: [bug-gawk] Overflow to Infinity
Date: Tue, 19 Jun 2018 12:55:20 -0700

Hello,

I did this test with Windows 7.  I get similar results when running gawk 4.2.1 with cygwin.

0 0
0.3 0.3
1e+30 1000000000000000019884624838656
1.2e+301 12000000000000000630057123062453042984453620000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1.2e+311 0
1.2e+321 0
1.2e+331 0
1.2e+931 0
1.2e+9999 0
1.2e+9999999 0

I would argue that the result should be 'inf' since the input string looks like a number.  Zero should be the decoding result when there is no leading number in the string but there are leading numbers.

There are lots of examples in which gawk will print 'inf' or 'nan'.

print  -log(0)        # inf

In this case it is the result of numeric function rather than the decoding of a field.  I would argue that the results should be consistent in behavior.

You are right in that printing 'inf' is problematic since one cannot read it back in again and have it decoded again as 'infinity'.  This is true with fields and with math functions.

+inf
-inf

This 'round-about' problem could be solved by outputting the sign to indicate it is numeric.  On input '+inf' would decode to positive infinity and 'inf' would be just a string.

Thanks.  Dan.

On 19 June 2018 at 05:06, Daniel Pettet <address@hidden> wrote:
Hello,

The following test program illustrates a problem with overflow of large numbers to what should be infinity.

BEGIN {
    n = split ("0 0.3 1e+30 1.2e+301 1.2e+311 1.2e+321 1.2e+331 1.2e+931 1.2e+9999 1.2e+9999999", a)

    for (i=1; i<=n; ++i)
        print a[i], +a[i]
}


With versions 4.1.4 and 4.2.1 the program output is:

0 0
0.3 0.3
1e+30 1000000000000000019884624838656
1.2e+301 12000000000000000630057123062453042984453622973297909858990249386141629495866898349436456500965374368524453325994606538123310278824325166907737506217440483794180646411118909644853962805537457080712427438819649599340973428467611690560895832913361709934951105465840682114057388033666356642385512806481920
1.2e+311 0
1.2e+321 0
1.2e+331 0
1.2e+931 0
1.2e+9999 0
1.2e+9999999 0

The conversions to numbers result in zeros rather than infinities.

Thanks.  Dan.


reply via email to

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