TCL scripting: errorInfo=integer value too large to represent

The username is of the format : 123456789110000-1234@something.com
With this below TCL procedure, I am trying add first and Sec Id and get third Id.
I checked in online compiler and it seems to work and add. However, when I am running this in my lab, I get error as "integer value too large to represent"

I alo tried removing the "int" from this line > $environ put New-Third [ expr int($FirstId+$SecId) ] to $environ put New-Third [ expr ($FirstId+$SecId) ] still error persists

TCL version: 8.5

Error

handleException: errMsg=integer value too large to represent; errorInfo=integer value too large to represent
    while executing
"expr int($FirstId+$SecId) "
    (procedure "disUser" line 11)
    invoked from within
"disUser $environ [ $request get User-Name ]"
    while executing
"expr int($FirstId+$SecId) "
    (procedure "disUser" line 11)
    invoked from within

Procedure

proc disUser { environ username } {
                if { [ regexp {^(\d{15})-(\d{1,4})@([a-zA-Z0-9\.\-]{1,50})$} $username dummy FirstId SecId Arn ] } {
                        $environ put New-First-Id $FirstId
                        $environ put New-Sec $SecId
                        ############Add the First and Sec Id to generate the Third
                        $environ put New-Third [ expr int($FirstId+$SecId) ] 
                        $environ put New-Arn $Arn   
                } else {
                        error "INVALID_USERNAME" \
                        "Source=[$environ get IP-Address];UserName=$username"
                }
        }

Without any TCL knowledge, I guess that 123456789110000 really seems a bit large for integer representation (in any tool / language / system). If you just want to concatenate the two variables, make them strings. If you need to do math with them, try float representation.

Assuming that expr in the code you showed us is the expr utility (and not a tcl built-in), you could use bc or dc instead of expr .

It's been a long time since I've written any TCL code, but to see how to use bc in shell code, try:

$ x=$(echo 123456789110000 + 1234 | bc) 
$ echo $x
123456789111234
$ 

Hi.

Noting that:

mathfunc manual page - Tcl Mathematical Functions

Stripping the statements down to this:

#!/usr/bin/env tclsh

# @(#) tcl1     Demonstrate tclsh feature.

puts stdout ""
set version [ info tclversion ]
set message " Hello, world from tclsh ($version)"
puts stdout $message

set first 123456789110000
set next  1234

set sum [expr {$first+$next}]
puts " Sum of $first plus $next is $sum"

produces:

./tcl1

 Hello, world from tclsh (8.6)
 Sum of 123456789110000 plus 1234 is 123456789111234

On a system like:

OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.7 (jessie) 
tclsh 8.6

Best wishes ... cheers, drl

1 Like