[1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2019-11-12 Thread Austin Group Bug Tracker


The following issue has a resolution that has been APPLIED. 
== 
http://austingroupbugs.net/view.php?id=1198 
== 
Reported By:geoffclare
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1198
Category:   Shell and Utilities
Type:   Error
Severity:   Objection
Priority:   normal
Status: Applied
Name:   Geoff Clare 
Organization:   The Open Group 
User Reference:  
Section:awk 
Page Number:2489 
Line Number:80031 
Interp Status:  Approved 
Final Accepted Text:See
http://austingroupbugs.net/view.php?id=1198#c4320. 
Resolution: Accepted As Marked
Fixed in Version:   
== 
Date Submitted: 2018-08-07 10:40 UTC
Last Modified:  2019-11-12 15:08 UTC
== 
Summary:Comparison of numeric string values in awk
== 

Issue History 
Date ModifiedUsername   FieldChange   
== 
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
http://austingroupbugs.net/view.php?id=1198#c4320.
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 agadminInterp Status--- => Proposed 
2019-03-16 06:32 agadminNote Added: 0004325  
2019-04-17 10:52 agadminInterp StatusProposed => Approved
2019-04-17 10:52 agadminNote Added: 0004369  
2019-11-12 15:08 geoffclare Status   Interpretation Required
=> Applied
==




[1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2019-04-17 Thread Austin Group Bug Tracker


The following issue has been UPDATED. 
== 
http://austingroupbugs.net/view.php?id=1198 
== 
Reported By:geoffclare
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1198
Category:   Shell and Utilities
Type:   Error
Severity:   Objection
Priority:   normal
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
http://austingroupbugs.net/view.php?id=1198#c4320. 
== 
Date Submitted: 2018-08-07 10:40 UTC
Last Modified:  2019-04-17 10:52 UTC
== 
Summary:Comparison of numeric string values in awk
== 

-- 
 (0004369) agadmin (administrator) - 2019-04-17 10:52
 http://austingroupbugs.net/view.php?id=1198#c4369 
-- 
Interpretation approved: 17 April 2019 

Issue History 
Date ModifiedUsername   FieldChange   
== 
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
http://austingroupbugs.net/view.php?id=1198#c4320.
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 agadminInterp Status--- => Proposed 
2019-03-16 06:32 agadminNote Added: 0004325  
2019-04-17 10:52 agadminInterp StatusProposed => Approved
2019-04-17 10:52 agadminNote Added: 0004369  
==




[1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2019-03-16 Thread Austin Group Bug Tracker


The following issue has been UPDATED. 
== 
http://austingroupbugs.net/view.php?id=1198 
== 
Reported By:geoffclare
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1198
Category:   Shell and Utilities
Type:   Error
Severity:   Objection
Priority:   normal
Status: Interpretation Required
Name:   Geoff Clare 
Organization:   The Open Group 
User Reference:  
Section:awk 
Page Number:2489 
Line Number:80031 
Interp Status:  Proposed 
Final Accepted Text:See
http://austingroupbugs.net/view.php?id=1198#c4320. 
== 
Date Submitted: 2018-08-07 10:40 UTC
Last Modified:  2019-03-16 06:32 UTC
== 
Summary:Comparison of numeric string values in awk
== 

-- 
 (0004325) agadmin (administrator) - 2019-03-16 06:32
 http://austingroupbugs.net/view.php?id=1198#c4325 
-- 
Interpretation Proposed: 16 March 2019 

Issue History 
Date ModifiedUsername   FieldChange   
== 
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
http://austingroupbugs.net/view.php?id=1198#c4320.
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 agadminInterp Status--- => Proposed 
2019-03-16 06:32 agadminNote Added: 0004325  
==




[1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2019-03-14 Thread Austin Group Bug Tracker


The following issue NEEDS AN INTERPRETATION. 
== 
http://austingroupbugs.net/view.php?id=1198 
== 
Reported By:geoffclare
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1198
Category:   Shell and Utilities
Type:   Error
Severity:   Objection
Priority:   normal
Status: Interpretation Required
Name:   Geoff Clare 
Organization:   The Open Group 
User Reference:  
Section:awk 
Page Number:2489 
Line Number:80031 
Interp Status:  --- 
Final Accepted Text:See
http://austingroupbugs.net/view.php?id=1198#c4320. 
== 
Date Submitted: 2018-08-07 10:40 UTC
Last Modified:  2019-03-14 15:46 UTC
== 
Summary:Comparison of numeric string values in awk
== 

Issue History 
Date ModifiedUsername   FieldChange   
== 
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
http://austingroupbugs.net/view.php?id=1198#c4320.
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  
==




[1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2019-03-14 Thread Austin Group Bug Tracker


A NOTE has been added to this issue. 
== 
http://austingroupbugs.net/view.php?id=1198 
== 
Reported By:geoffclare
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1198
Category:   Shell and Utilities
Type:   Error
Severity:   Objection
Priority:   normal
Status: New
Name:   Geoff Clare 
Organization:   The Open Group 
User Reference:  
Section:awk 
Page Number:2489 
Line Number:80031 
Interp Status:  --- 
Final Accepted Text: 
== 
Date Submitted: 2018-08-07 10:40 UTC
Last Modified:  2019-03-14 15:45 UTC
== 
Summary:Comparison of numeric string values in awk
== 

-- 
 (0004320) Don Cragun (manager) - 2019-03-14 15:45
 http://austingroupbugs.net/view.php?id=1198#c4320 
-- 
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.
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. 

Issue History 
Date ModifiedUsername   FieldChange   
== 
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  
==




Re: [1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2018-08-08 Thread Robert Elz
Date:Wed, 8 Aug 2018 14:42:38 +0100
From:Stephane Chazelas 
Message-ID:  <20180808134238.ga16...@chaz.gmail.com>

  | By the way, you can also convert a string to numeric with:
  |  if (x+0 < y+0)

Yes, thanks, I knew how to convert, just not whether it was
supposed to be necessary or not.   In the actual script, the
variables should be numeric, the real bug is that one of them
is defined to be a string.

  | BSDs at the time. I don't know if they're still affected, you
  | may want to check on NetBSD.

NetBSD uses nawk, which is still affected it seems.   I will see
if that can get fixed.

kre

ps: I do not believe that "print x < y" is valid awk, because of the ambiguity
with "print x > y" I assume, and that it would be bizarre to allow < and not >
in that context.   To use the relational ops, parentheses are needed, as
in "print (x < y)".




Re: [1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2018-08-08 Thread Stephane Chazelas
2018-08-08 16:26:25 +0700, Robert Elz:
> Date:Wed, 8 Aug 2018 09:28:57 +0100
> From:Geoff Clare 
> Message-ID:  <20180808082857.GA6879@lt2.masqnet>
> 
>   | No it can't.
> 
> Thanks, that's sort of what we thought, but the script exists, and
> rather than blindly just "fix" it we wanted to be sure.
> 
> It "works" as it is, I believe, puerly because the "numbers" it is
> comparing all are the same order of magnitude (have the same
> number of digits) so a string comparison gives the same answer
> as a numeric one (which is what it should be doing) would.
[...]

By the way, you can also convert a string to numeric with:

 if (x+0 < y+0)

It also covers the case where the content of x is from one of
those sources that can be considered as numeric strings (like
-v, $1...) but are not considered as such because they have
trailing garbage.

For instance:

   awk -v 'x=10$' -v 'y=2$' 'BEGIN{print x < y}'

would print 1.

   awk -v 'x=10$' -v 'y=2$' 'BEGIN{print 0+x < 0+y}'

would print 0 as x and y have been converted to 10 and 2
numbers.

BTW, some people use:

   awk -v 'x=10$' -v 'y=2$' 'BEGIN{print +x < +y}'

But that's not portable. In historical implementations, the
unary + is a no-op and doesn't force conversion to number.
That's a conformance bug. I did report it to bwk, but not to
BSDs at the time. I don't know if they're still affected, you
may want to check on NetBSD.

It was discussed here a few years ago:
http://thread.gmane.org/gmane.comp.standards.posix.austin.general/11391

-- 
Stephane



Re: [1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2018-08-08 Thread Geoff Clare
Robert Elz  wrote, on 08 Aug 2018:
>
> This is not really about issue 1198, but a question raised by
> thinking about issue 1198 ...
> 
> The question is, when an awk script does (not on the command
> line, but in the script)
> 
>   x="10"
> 
> can the value of x ever be considered a numeric string (in the
> awk definition technical sense) ?

No it can't.

The standard has a list of 8 sources of string values that are
eligible for it to be considered a numeric string, and variable
assignment from a string literal does not qualify as any of them.

-- 
Geoff Clare 
The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England



Re: [1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2018-08-07 Thread Robert Elz
This is not really about issue 1198, but a question raised by
thinking about issue 1198 ...

The question is, when an awk script does (not on the command
line, but in the script)

x="10"

can the value of x ever be considered a numeric string (in the
awk definition technical sense) ?

This arose because a real-life awk script is written (for whatever
reason) starting something like

awk "
BEGIN {
x = \"$x\" ;
}
/* and all the rest */
"

and 'x' is clearly intended to be treated numerically.I suspect that
the embedded quotes are  to allow for the possibility that the shell
variable x (the $x) is not set (or null), since
x= ;
is not valid awk syntax... I would have written it (in the BEGIN block) ...

x = ${x:-0};
or
${x:+x=${x};}

or just made it a cmd line var assignment (I suspect that was not done as
there are actually quite a lot of them, not just this one) but I did not write 
it.

kre



[1003.1(2016)/Issue7+TC2 0001198]: Comparison of numeric string values in awk

2018-08-07 Thread Austin Group Bug Tracker


The following issue has been SUBMITTED. 
== 
http://austingroupbugs.net/view.php?id=1198 
== 
Reported By:geoffclare
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1198
Category:   Shell and Utilities
Type:   Error
Severity:   Objection
Priority:   normal
Status: New
Name:   Geoff Clare 
Organization:   The Open Group 
User Reference:  
Section:awk 
Page Number:2489 
Line Number:80031 
Interp Status:  --- 
Final Accepted Text: 
== 
Date Submitted: 2018-08-07 10:40 UTC
Last Modified:  2018-08-07 10:40 UTC
== 
Summary: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
== 

Issue History 
Date ModifiedUsername   FieldChange   
== 
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 => --- 
==