Tags: 123srand, argument, claimes, clicks, clock, expr, floating-point, milliseconds, programming, srand, tcl, value
srand() claimes to get a floating-point value from "clock clicks"?
On Programmer » TCL
2,516 words with 2 Comments; publish: Wed, 07 May 2008 10:05:00 GMT; (20046.88, « »)
Hello,
something I don't really understand:
% expr {srand([clock milliseconds])}
can't use floating-point value as argument to srand
% expr {srand([clock microseconds])}
can't use floating-point value as argument to srand
% expr {srand([clock clicks])}
can't use floating-point value as argument to srand
% expr {srand(wide([clock clicks]))}
can't use floating-point value as argument to srand
% expr {srand(int([clock clicks]))}
0.8654289347424307
% expr {srand([clock seconds])}
0.1414733348141766
Is there still some work to be done to make the math functions support
wide integers?
I assume this because of the same error message, when using the wide()
conversion.
Should I file a bug?
Best regards,
Martin Lemburg
UGS - Transforming the Process of Innovation
http://tcl-program.itags.org/q_tcl_147449.html
All Comments
Leave a comment...
- 2 Comments

- MartinLemburg.tcl-program.itags.org.UGS wrote:
> % expr {srand([clock milliseconds])}
> can't use floating-point value as argument to srand
Upgrade to CVS sources (or maybe the most recent ActiveTcl?)
to get an improved error message:
% expr {srand([clock milliseconds])}
integer value too large to represent
The srand() function accepts only those values that pass
[string is integer]:
% string is integer [clock milliseconds]
0
That is, only values that fit in the C "long" type are acceptable.
This has always been the case with the srand() function.
> Should I file a bug?
You might file a request to truncate larger integers to the "long"
range instead of throwing an error. Compatibility considerations
would have to be looked into.
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter.tcl-program.itags.org.nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|_______________________________________
_______________________________|
#1; Wed, 07 May 2008 10:06:00 GMT

- Hi Don,
I tested this with a tclkit of the tcl version 8.5a4.
Yes, I would like to suggest an automatic truncation to a long value or
if not possible a better error message! ;-)
So I'll do the next days on sourceforge.net.
Nice wend!
Martin Lemburg
UGS - Transforming the Process of Innovation
#2; Wed, 07 May 2008 10:07:00 GMT