Forum Discussion

Radoslaw_74539's avatar
Radoslaw_74539
Icon for Nimbostratus rankNimbostratus
Apr 16, 2010

tcl set command limit in iRule

Hi There,

 

 

I'm trying to find some info about the limitation for the tcl set command in iRule.

 

 

Basically for the following code:

 

 

when RULE_INIT {

 

set ::i 0

 

set ::reqkey rrr

 

}

 

when HTTP_REQUEST {

 

HTTP::header insert "Cookie" $::reqkey=$::i

 

incr ::i 1

 

}

 

 

what is the maximal value I can expect the variable "i" can be assigned to?

 

 

I'm new in TCL but have some programme background form c,c++, perl/python.

 

 

I looked at below links and try to search in the forum. But didn't find my answer.

 

http://tmml.sourceforge.net/doc/tcl/set.html

 

http://tmml.sourceforge.net/doc/tcl/SetVar.html

 

 

Thanks in advance

 

Rado

 

 

1 Reply

  • Hi Rado,

    All current iRules versions are based on TCL 8.4. TCL 8.4 supports a max integer of 2^63:

    From http://en.wikibooks.org/wiki/Tcl_Programming/Introduction

    The maximal positive integer can be determined from the hexadecimal form, with a 7 in front, and else all Fs. Tcl from 8.4 can use "wide integers" of 64 bits, and the maximum integer there is

    % expr 0x7fffffffffffffff

    9223372036854775807

    Demonstration: one more, and it turns into the minimum integer:

    % expr 0x8000000000000000

    -9223372036854775808

    Bignums: from Tcl 8.5, integers can be of arbitrary size, so there is no maximum integer anymore. Say, you want a big factorial:

    % proc tcl::mathfunc::fac x {expr {$x < 2? 1: $x * fac($x-1)}}

    % expr fac(100)

    93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

    
    
    when RULE_INIT {
       log local0. "\[expr 0x7fffffffffffffff\]: [expr 0x7fffffffffffffff]"
       log local0. "\[expr 0x8000000000000000\]: [expr 0x8000000000000000]"
    }
    

    : [expr 0x7fffffffffffffff]: 9223372036854775807

    : [expr 0x8000000000000000]: -9223372036854775808

    Aaron