An old Tcl problem has come back to haunt me.
--------------------
TYPES, OVERFLOW, AND PRECISION
Conversion among internal representations for integer, floating-point,
and string operands is done automatically as needed. For arithmetic computations, integers are used until some floating-point number is
introduced, after which floating-point is used. For example,
expr {5 / 4}
returns 1, while
expr {5 / 4.0}
expr {5 / ( [string length "abcd"] + 0.0 )}
both return 1.25. Floating-point values are always returned with a "."
or an e so that they will not look like integer values. For example,
expr {20.0/5.0}
returns 4.0, not 4.
--------------------
That sounds like a horrible pitfall to me.
I've been writing some code, stunned because a certain division operation
was adamantly returning 0. It took me some time to realize I had to convert
at least one of the numbers into float:
set ::tcl_precision 8
set x [::tcl::mathfunc::double $x]
set result [expr $x / $y]
I don't really mind doing that, but what if I run a series of calculations whose numbers I cannot predict and a couple of integers are the results of
some of those calculations and they end up being calculated against each
other and Tcl outputs an incorrect integer result merely because those
two numbers happened to be integers?
That's how trains get derailed and spaceships explode, isn't it?
What do you sage Tclers have to say about this?
--
Luc
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)