|
From: | Daniel Pettet |
Subject: | Re: [bug-gawk] Overflow to Infinity |
Date: | Tue, 19 Jun 2018 16:03:06 -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 120000000000000006300571230624530429844536200000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 00
1.2e+311 0
1.2e+321 0
1.2e+331 0
1.2e+931 0
1.2e+9999 0
1.2e+9999999 0I 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) # infIn 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-infThis '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 120000000000000006300571230624530429844536229732979098589902 493861416294958668983494364565 009653743685244533259946065381 233102788243251669077375062174 404837941806464111189096448539 628055374570807124274388196495 993409734284676116905608958329 133617099349511054658406821140 573880336663566423855128064819 20
1.2e+311 0
1.2e+321 0
1.2e+331 0
1.2e+931 0
1.2e+9999 0
1.2e+9999999 0The conversions to numbers result in zeros rather than infinities.Thanks. Dan.
[Prev in Thread] | Current Thread | [Next in Thread] |