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 2018-08-07 10:40
Reporter geoffclare View Status public  
Assigned To
Priority normal Resolution Open  
Status New  
Name Geoff Clare
Organization The Open Group
User Reference
Section awk
Page Number 2489
Line Number 80031
Interp Status ---
Final Accepted Text
Summary 0001198: Comparison of numeric string values in awk
[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 [^] and [^] 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 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, ...
... 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
$expr | Field reference | Uninitialized or string | N/A
Tags No tags attached.
Attached Files

- Relationships

There are no notes attached to this issue.

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

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