Skip to content
Tcl Source Code History Of Ticket 576512ffffffffff
Login

History Of Ticket 576512ffffffffff

Artifacts Associated With Ticket 576512ffffffffff

  1. Ticket change [2a56a18201] (rid 118544) by nobody on 2002-07-02 18:20:03:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      
      Using 8.2.3 (SGI), 8.3.1, or 8.3.3, (both linux)
      the following behavior is observed:
      
      % set x [expr 1.2*3.0]
      3.6
      
      % if {3.6 > $x} {puts "3.6 is greater than $x!"}
      3.6 is greater than 3.6!
      
      % puts [expr 3.6 > $x]
      0
      
      
      So, apparently the expr procedure evaluates differently
      than the parsing of the if conditional. 
      
      I would rather not make all of my if statements like:
      
      if {[expr 3.6 > $x] == 1} {...}
      
    4. foundin initialized to: "None"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "None"
    10. title initialized to: "Math problem."
    11. type initialized to: "Bug"
  2. Ticket change [47bac72330] (rid 99753) by msofer on 2002-07-03 01:56:59:

    1. closedate changed to: "2002-07-02T18:56:59"
    2. closer changed to: "msofer"
    3. icomment:
      Logged In: YES 
      user_id=148712
      
      This is because the internal representation of (1.2*3.0)
      *is* larger than the internal representation of (3.6) -
      floats are weird :(
      
      Now, when you do 
         puts [expr 3.6 > $x] 
      expr will do double substitution - essentially, it builds
      the string
         "3.6 > $x"
      with '$x' replaced by the string representation of its
      value, then parses this string and finally evaluates the
      expression.The roundtrip via the string rep of '$x' causes
      the equality due to rounding in the float-to-string conversion.
      
      If you do instead
          puts [expr {3.6 > $x}]
      preventing the conversion to string, you obtain 1. So: it is
      consistent, the problem that they aren't equal is intrinsic
      to the binary representation of floats. This is inherited
      from C.
      
      See http://wiki.tcl.tk/879 for more troublesome examples
      with real numbers.
      
      
    4. login: "msofer"
    5. mimetype: "text/plain"
    6. resolution changed to: "Invalid"
    7. status changed to: "Pending"
    8. username: "msofer"
  3. Ticket change [c44d61bf60] (rid 111825) by msofer on 2002-07-03 01:58:54:

    1. assignee changed to: "msofer"
    2. status changed to: "Open"
  4. Ticket change [ccf979802e] (rid 95800) by msofer on 2002-07-03 02:00:40:

    1. closedate changed to: "2002-07-02T19:00:40"
    2. closer changed to: "msofer"
    3. icomment:
      Logged In: YES 
      user_id=148712
      
      Oops: first I forget to assign to myself, then I
      inadvertedly change the status ...
      
      
    4. login: "msofer"
    5. mimetype: "text/plain"
    6. status changed to: "Pending"
    7. username: "msofer"
  5. Ticket change [e65fd3af66] (rid 104282) by dgp on 2002-07-03 02:10:33:

    1. icomment:
      Logged In: YES 
      user_id=80530
      
      "So, apparently the expr procedure evaluates differently
      than the parsing of the if conditional"
      
      No, you will find that
      
          [expr {3.6 > $x}]
      
      always gives the same result as
      
         if {3.6 > $x} {...}
      
      You did not enclose the expression in
      braces, so two rounds of substituion
      occurred, including a translation from
      double -> string -> double.  Such
      translations often lose precision and
      change the precise floating point value.
      
      Seeking arbitrarily precise answers involving
      floating point values is a mistake in the
      first place.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. status changed to: "Open"
    5. username: "dgp"
  6. Ticket change [e1b71ef9b0] (rid 87503) by dkf on 2002-07-06 05:36:55:

    1. closedate changed to: "2002-07-05T22:36:55"
    2. closer changed to: "dkf"
    3. status changed to: "Closed"