Gorm Haug Eriksen <g.h.eriksen@usit.uio.no> said:
Gorm> cotty > expr 2147483647
Gorm> 2147483647
Gorm> scotty > expr 2147483648
Gorm> -2147483648
Gorm> scotty > =
Gorm> A trivial soloution != hack C source :)
Gorm> It's also not enought with a u_long (4294967295), but I realy
Gorm> need a double :-/
Gorm> I have tested the double() function in Tcl, but there seems to
Gorm> come some new problems because Tcl doesn't recognice this as a
Gorm> int.
Gorm> I am sorry to bother this list with such noise like this, but
Gorm> for my defense, I have checked both The Tcl Bible (John O.'s
Gorm> Tcl and the Tk Toolkit), and the faq, but couldn't get any
Gorm> good answers (the only answer i got from the book was that Tcl
Gorm> should fix this, much like what perl does).
The expr command of Tcl is really ugly and can't deal with unsigned
values. In your example, the number is first converted to an internal
int value (thats where you get the sign) and this signed number is put
into the function double().
Here is a double proc that tries to extend a number to a double by
just appending a ".0". It works somehow, but it is just an ugly fix
around the broken expr command in Tcl (at least if Tcl claims to be a
(very?) high level language):
proc double n {
if [regexp {^[1-9][0-9]+\.0+$} "$n.0"] {
set n "$n.0"
}
return [expr double($n)]
}
I do not know if it handles all cases correctly, but it takes care to
handle those numbers that start with a leading 0 (which could be octal
or hexadecimal numbers). The final call to expr is needed in any case
to get the result formated according to tcl_precision (which is also
some kind of a `funny' feature).
Juergen