Artifacts Associated With Ticket 50dfde2216
Ticket change [10641a1468] (rid 141283) by gbrmmt1134 on 2015-03-05 07:59:50:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Found problem with "expr" while doing calculations For example : % expr (576.64 - 554.176) * 1.0 / 0576 39.0 % expr int((576.64 - 554.176) * 1.0 / 0576) 38 How come the int for 39.0 will become 38?
- foundin initialized to: "8.4"
- is_private initialized to: "0"
- login: "gbrmmt1134"
- priority initialized to: "5 Medium"
- private_contact initialized to: "1f9dc978126c843d03707c55bd407445464d0f64"
- resolution initialized to: "None"
- severity initialized to: "Severe"
- status initialized to: "Open"
- submitter initialized to: "gbrmmt1134"
- subsystem initialized to: "16. Commands A-H"
- title initialized to: "facing issue with expr"
- type initialized to: "Bug"
Add attachment "BugInTcl.png" [514eb0d883] (rid 141284) by gbrmmt1134 on 2015-03-05 08:00:41.
Ticket change [2460ea47a8] (rid 141285) by dkf on 2015-03-05 10:57:36:
- assignee changed to: "kbk"
- closedate changed to: "2457086.95667612"
- closer changed to: "dkf"
- comment changed to:
Found problem with "expr" while doing calculations For example : % expr (576.64 - 554.176) * 1.0 / 0.576 39.0 % expr int((576.64 - 554.176) * 1.0 / 0.576) 38 How come the int for 39.0 will become 38?
- icomment:
The issue is that the calculation isn't yielding the value that you think it is; when I try with Tcl 8.5 or 8.6 (both of which are <i>much</i> more careful in the rendering of floating point numbers than 8.4 and before were), I get this: <pre>% expr (576.64 - 554.176) * 1.0 / 0.576 38.9999999999999</pre> Binary floating point numbers (such as Tcl uses, along with <i>many</i> other programming languages) are fundamentally not capable of delivering perfectly accurate calculations for every value you can type in, in a way that is precisely analogous to how you can't represent the result of dividing 1 by 3 in a finite number of decimals. For more info see <a href="http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html">this classic paper</a>. <p> The one interesting thing about Tcl is that we now guarantee to use the minimum number of digits to represent a number when converting from the floating point internal representation to the decimal string form, subject to the constraint that the reverse operation (string-to-IEEE-<tt>double</tt>) gives exactly the same thing. That is a non-trivial guarantee; it takes quite a lot of code in Tcl's implementation to achieve it. If you really want to use a smaller number of digits than what is properly necessary, the <tt>format</tt> command is the right approach, though you should be aware that this will do some rounding.
- login: "dkf"
- mimetype: "text/html"
- resolution changed to: "Invalid"
- severity changed to: "Cosmetic"
- status changed to: "Closed"
- subsystem changed to: "47. Bytecode Compiler"
- username: "dkf"