bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] gawk erroneous comparison with large negative exponents


From: Aharon Robbins
Subject: Re: [bug-gawk] gawk erroneous comparison with large negative exponents
Date: Mon, 13 Apr 2015 10:40:21 +0300
User-agent: Heirloom mailx 12.5 6/20/10

Hi Mr. Katzman.

Thank you for taking the time to send in a bug report; I appreciate it.

The issue you report is exactly because you're at the limit of what
can be represented by double precision floating point numbers.

Ultimately, gawk relies on the C library strtod() function to convert
a string value to a number, and since an exponent of -308 is out of
range, strtod() fails to do.  Thus, gawk treats 1e-308 as a string and
does a string comparison to 0.5.  This fails.

When adding 0, the conversion from "1e-308" becomes 0. 0 + 0 is still
less than 0.5, so it "succeeds".

If perl handles this differently, that's great, but awk doesn't work
that way. :-)  I believe that this is pretty clearly documented.

Also, 3.1.7 is quite old; 4.1.1 is current and I hope to release 4.1.2
Real Soon Now.  The behavior you note hasn't changed in 4.1.x though.

Thanks,

Arnold



reply via email to

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