tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Proposed POSIX change to the awk spec



In response to bug report 1198
	http://austingroupbugs.net/view.php?id=1198

which said (inter alia):

   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.

Use the URL above to see the complete original report.

The response was...

   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.

[that's boilerplate text that simply means a change is going to be made...]

   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.

[that's issue specific boilerplate text which means the same]

The rest of this is what is to happen.   Ignore the "not part of
this interpretation" - that's also boilerplate - the "notes to the
editor" are exactly what change is to be made:

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


If anyone has any comments about that (perhaps aside from "obviously"
or similar), they need to be made before April 16.   If needed, if you
don't want to (or aren't able to) send comments yourself, I can forward.

kre



Home | Main Index | Thread Index | Old Index