|
From: | Ed Morton |
Subject: | Re: [bug-gawk] Unstated differences between gawk and POSIX |
Date: | Fri, 3 Aug 2018 10:58:02 -0500 |
User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 |
OK, so apparently gawk really doesn't behave per the POSIX standard
when comparing numeric-string to numeric-string: In the Expressions In Awk section POSIX says: Comparisons (with the '<', "<=", "!=", "==", '>', and ">=" operators) shall be made numerically if both operands are numeric, if one is numeric and the other has a string value that is a numeric string, or if one is numeric and the other has the uninitialized value. Otherwise, operands shall be converted to strings as required and a string comparison shall be madeso numeric-string to numeric-string should be a string comparison while gawk does a numeric comparison: $ echo '07 7.0' | gawk '$1 == $2'That behavior is as documented under Variable Typing in the gawk manual. I wouldn't want the default behavior of gawk to change as I think it makes sense but I also think SOMETHING should happen to give users a heads up. Maybe gawk should do as POSIX defines when run with --posix and maybe there should be a note in the documentation about it? Or maybe someone should work on getting the POSIX spec updated to reflect how gawk and other awks actually behave (idk how you'd even go about that but if you do....). Thoughts? Ed. On 8/2/2018 10:30 AM, Ed Morton wrote:
When reading the POSIX standard for gawk recently (https://groups.google.com/d/msg/comp.lang.awk/qYhgpz08pN8/ihidWMLmCQAJ) I noticed a couple of cases wrt comparisons where gawk behaves differently from what [parts of] the POSIX spec say. I posted a question about it at comp.lang.awk (https://groups.google.com/d/msg/comp.lang.awk/qYhgpz08pN8/9wbMr9XKCQAJ) to see if I might be just misunderstanding the spec but that doesn't seem to be the case. The issues are: |
[Prev in Thread] | Current Thread | [Next in Thread] |