Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling integer overflow in TCL

Status
Not open for further replies.

itzmesri

Programmer
Sep 7, 2009
5
GB
Hi,
I am facing integer overflow issues in TCL. All I want to do is to calculate an alarm timer(in milli seconds) upon elapsing which some functionality has to be kick started.

But the calculation (since it is in milliseconds) results in a negative value.

Is there are a way to over come this issue ?
 
It depends on how many days you want to be represented in the timeout. An integer in Tcl is a C long, so it should hold at least 20 days expressed in milliseconds, before going to the negative side.

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Yes, the aim is to have the number of days configurable. I am looking into a range of around 50 to 100 days. Is there an alternative way to handle this problem ?
 
Don't see an immediate solution, as the field to after (if you are using it) is an integer.
What you could do is writing an after command that, for the first n executions, will execute after again, and only at n+1 will execute the actual command.
n and the delay (less than 20 days) would be calculated to sum up to the total delay.

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Thanks.
Yes I am in deed using the after command :)
I am not able to quite get your previous suggestion. I presume you mean to say that we use the after command in increments and calculate the total delay ?
 
Well something like
Code:
set n [expr round($timeout_in_days/20)]
set timeout_ms [expr int($timeout_in_days/$n*86400000)]
after $timeout_ms repeat_one $n $timeout_ms
proc repeat_one {n t} {
  incr n -1
  if {$n} {
    after $t repeat_one $n $t
  } else {
    do_whatever
  }
}

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top