Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 47bac7233080705be79d7c58f10a42758f2e6969
Ticket: 576512ffffffffffffffffffffffffffffffffff
Math problem.
User & Date: msofer on 2002-07-03 01:56:59
Changes

  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"