Austin Group Defect Tracker

Aardvark Mark III


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001198 [1003.1(2016)/Issue7+TC2] Shell and Utilities Objection Error 2018-08-07 10:40 2019-04-17 10:52
Reporter geoffclare View Status public  
Assigned To
Priority normal Resolution Accepted As Marked  
Status Interpretation Required  
Name Geoff Clare
Organization The Open Group
User Reference
Section awk
Page Number 2489
Line Number 80031
Interp Status Approved
Final Accepted Text See Note: 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/A
to:
$expr | Field reference | Uninitialized or string | N/A
Tags tc3-2008
Attached Files

- Relationships

-  Notes
(0004320)
Don Cragun (manager)
2019-03-14 15:45
edited on: 2019-03-14 15:55

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...

(0004325)
agadmin (administrator)
2019-03-16 06:32

Interpretation Proposed: 16 March 2019
(0004369)
agadmin (administrator)
2019-04-17 10:52

Interpretation approved: 17 April 2019

- Issue History
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 Note: 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


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker