Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 38506fd9d44712ab65734a9943df721a87beb764
Ticket: ef5373e6fa0617ee02f201c6c8f41746678c5afb
expr, literal numeric values, and string comparisons
User & Date: dkf on 2016-10-30 17:40:11
Changes

  1. comment changed to:
    The documentation for <code>expr</code> provides seven rules for operand
    syntax.  Of those, the value <code>0x12</code> matches rule 1, and only rule 1:
    "<i>... a numeric value, either integer or floating-point</i>".  Therefore,
    <code>0x12</code> is unambiguously a numeric value.  The string representation
    of <code>0x12</code> is <code>18</code>, as illustrated by the result of
    <code>[expr 0x12]</code>.  Furthermore, the documentation states that operands
    that are not numeric or boolean must be quoted.  It's well-accepted that only
    numeric operands can appear unquoted in an expression.  Finally, the
    documentation states that in order to compare a numeric operand to an operand
    that can't be interpreted as numeric, the string representation for the numeric
    operand is generated.  Consider
    
    <code><verbatim>
    expr {{0y} > 0x12}
    </verbatim></code>
    
    . Since <code>0x12</code> is numeric, and its string representation is
    <code>18</code>, the previous command should produce the same result as
    
    <code><verbatim>
    expr {{0y} > {18}}
    </verbatim></code>
    
    . However, this isn't the case.  The result of the first command is <tt>1</tt>, and
    the result of the second is <tt>0</tt>.
    
  2. login: "dkf"
  3. mimetype: "text/plain"