View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001198 | 1003.1(2016/18)/Issue7+TC2 | Shell and Utilities | public | 2018-08-07 10:40 | 2024-06-11 09:08 |
Reporter | geoffclare | Assigned To | |||
Priority | normal | Severity | Objection | Type | Error |
Status | Closed | Resolution | Accepted As Marked | ||
Name | Geoff Clare | ||||
Organization | The Open Group | ||||
User Reference | |||||
Section | awk | ||||
Page Number | 2489 | ||||
Line Number | 80031 | ||||
Interp Status | Approved | ||||
Final Accepted Text | See 0001198:0004320. | ||||
Summary | 0001198: Comparison of numeric string values in awk | ||||
Description | [The following was reported to The Open Group help desk.] The "Expressions In Awk" section of the standard 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 made --- That's means that when a comparison involves 2 numeric strings it is a string comparison but of course in reality in all awks it is treated as a numeric comparison so that, for example, this: echo '5.0 10.0' | awk '$1 < $2' evaluates to true rather than false. There are some other confusing/misleading statements (at best) in the standard around the type of input fields and their value that could be written far more clearly - see https://groups.google.com/d/msg/comp.lang.awk/qYhgpz08pN8/9wbMr9XKCQAJ and https://stackoverflow.com/q/51632945/1745001 for discussions that have taken place recently on different forums around this area. [The comp.lang.awk discussion also talks about uninitialized fields behaving differently than uninitialized variables in some awks when compared to 0, but I think the standard is clear and intends what it says, so this is simply non-conforming behaviour in those awks. I think it is certainly undesirable for uninitialized fields to behave differently than uninitialized variables.] [The stackoverflow.com discussion is also about uninitialized fields but includes an answer which points out that the expressions table has this entry: Syntax | Name | Type of Result | Associativity $expr | Field reference | String | N/A which conflicts with the descriptive text in that it implies field variables always yield string values when used in an expression.] | ||||
Desired Action | On page 2489 line 80031 section awk change:... shall be made numerically if both operands are numeric, ...to: ... shall be made numerically if both operands are numeric, if both have string values that are numeric strings, ... On page 2485 line 79876 section awk change: $expr | Field reference | String | N/Ato: $expr | Field reference | Uninitialized or string | N/A | ||||
Tags | tc3-2008 |
|
Interpretation response ------------------------ The standard states that numeric strings are compared as strings, and conforming implementations must conform to this. However, concerns have been raised about this which are being referred to the sponsor. On the question of whether an uninitialized field has a string value, the standard is unclear on this issue, and no conformance distinction can be made between alternative implementations based on this. This is being referred to the sponsor. Rationale: ------------- This is not the intended behavior. Notes to the Editor (not part of this interpretation): ------------------------------------------------------- Make the following changes: On page 2485 line 79876 section awk change: $expr | Field reference | String | N/A to: $expr | Field reference | Uninitialized or string | N/A On page 2489 line 80031-80033 section awk change: 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... to: 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, . if both have string values that are numeric strings, or . if one is numeric and the other has the uninitialized value. Otherwise... |
|
Interpretation Proposed: 16 March 2019 |
|
Interpretation approved: 17 April 2019 |
Date Modified | Username | Field | Change |
---|---|---|---|
2018-08-07 10:40 | geoffclare | New Issue | |
2018-08-07 10:40 | geoffclare | Name | => Geoff Clare |
2018-08-07 10:40 | geoffclare | Organization | => The Open Group |
2018-08-07 10:40 | geoffclare | Section | => awk |
2018-08-07 10:40 | geoffclare | Page Number | => 2489 |
2018-08-07 10:40 | geoffclare | Line Number | => 80031 |
2018-08-07 10:40 | geoffclare | Interp Status | => --- |
2019-03-14 15:45 | Don Cragun | Note Added: 0004320 | |
2019-03-14 15:46 | Don Cragun | Final Accepted Text | => See 0001198:0004320. |
2019-03-14 15:46 | Don Cragun | Status | New => Interpretation Required |
2019-03-14 15:46 | Don Cragun | Resolution | Open => Accepted As Marked |
2019-03-14 15:46 | Don Cragun | Description Updated | |
2019-03-14 15:46 | Don Cragun | Tag Attached: tc3-2008 | |
2019-03-14 15:55 | Don Cragun | Note Edited: 0004320 | |
2019-03-16 06:32 | agadmin | Interp Status | --- => Proposed |
2019-03-16 06:32 | agadmin | Note Added: 0004325 | |
2019-04-17 10:52 | agadmin | Interp Status | Proposed => Approved |
2019-04-17 10:52 | agadmin | Note Added: 0004369 | |
2019-11-12 15:08 | geoffclare | Status | Interpretation Required => Applied |
2024-06-11 09:08 | agadmin | Status | Applied => Closed |