Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 751e75aef21c0e93997645a0e86d370f6bef702c869699a084abc7f3e563a028
Ticket: b8e9a9a97f0d8be15bd549239ec89aa58c11f3f4
expr 52 * 0.001 = 0.052000000000000005
User & Date: anonymous on 2019-03-08 23:47:17
Changes

  1. comment changed to:
    It seems tcl needs to consider how to handle math correctly. See the math example below. It will mess up the results in most of the cases, as long as the user does some simple math.
    
    We know it is a floating point number problem for computer and many computer languages. But it is still good to have a better solution than "set tcl_precision 12".
    
    52 * 0.001 = 0.052000000000000005
    0.52 * 0.01 = 0.005200000000000001
    0.1 + 0.2 = 0.30000000000000004
    
    I can reproduce this issue in Tcl 8.6.8 for Windows and Tcl 8.5.9 for Windows.
    
    (bin) 1 % expr 1 + 3
    4
    (bin) 2 % expr 52 + 3
    55
    (bin) 3 % expr 52 * 0.01
    0.52
    (bin) 4 % expr 52 * 0.001
    0.052000000000000005
    (bin) 5 % expr 0.52 * 0.01
    0.005200000000000001
    
    
    (bin) 8 % expr 0.1 + 0.2
    0.30000000000000004
    
  2. login: "anonymous"
  3. mimetype: "text/plain"