Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Another [string is integer] inconsistency

Closed / Invalid1230346fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-06-30 13:19:20
Maybe related to bug [ 718878 ].

On a 32bit Linux system using Tcl 8.4.9:

% set foo 4294967295
4294967295
% string is integer $foo
1

% set foo 4294967296
4294967296
% string is integer $foo
0

% set foo 2147483648
2147483648
% string is integer $foo
1

% set foo 2147483647
2147483647
% string is integer $foo
1

On a 64bit Solaris 5.8 system using a 64bit Tcl 8.4.9:

% set foo 4294967295
4294967295
% string is integer $foo
0

% set foo 4294967296    
4294967296
% string is integer $foo
0

% set foo 2147483648
2147483648
% string is integer $foo
0

% set foo 2147483647
2147483647
% string is integer $foo
1

So there are different results in the range from
2147483648 (1<<31) up to (and including) 4294967295
((1<<32)-1).

-- Matthias Kraft
dkf Ticket [1230346fff]: 1 change [History diff]2005-06-30 20:35:24
dgpplain2005-06-30 21:09:09
Logged In: YES 
user_id=80530


[string is integer] is meant to tell you
whether a value can have
Tcl_GetIntFromObj() called on it.

Since sizeof(int) can be different on
different systems, so can the results
of [string is integer].

That said, your 64-bit results look wrong.
matzekplain2005-06-30 23:23:02
Logged In: YES 
user_id=330806

Well, from my point of view I don't care about
Tcl_GetIntFromObj(). Script level is what counts, if script
level commands are used. I want to know if the user or
system provided a valid integer, not a string, nor a double
or whatever ...

The big numbers are essential, as I am going to check
whether or not I have enough place on the filesystem (e. g.
in this case for creating databases). Currently I use
[regexp -- {^-?[0-9]+$} $size] to validate the value I got
from the system. But I do it quite a number of times, so I'd
like to get rid of regexp, if there is a faster method...

-- Matthias Kraft
dgpplain2005-06-30 23:29:59
Logged In: YES 
user_id=80530


Actually, yes you do care.

Some commands accept only
those arguments that pass
Tcl_GetIntFromObj.  

For example,

  [lindex $list $index]

Forgetting for a moment the special
forms "end-", etc. for indices, if $index
is a string of digits, then you need then
to be digits that pass [string is integer $index].

% string is integer 9999999999
0
% lindex c 9999999999
bad index "9999999999": must be integer?[+-]integer? or
end?[+-]integer?

So, you need to choose the
validation command that matches your
intended use.  It might be
[string is wideinteger].  It might be your
regexp.  All depends on what your
eventual use will accept/reject.  Choose
the matching validator.
kennykbplain2005-08-06 02:28:32
Logged In: YES 
user_id=99768

I think that Matthias needs the 8.5 [string is wide]
functionality.
kennykbplain2005-11-05 02:40:42
Logged In: YES 
user_id=99768

In 8.5, we have [string is integer], [string is wideinteger] and
[string is bignum].  In 8.4, we have [string is integer] and
[string is wideinteger].  The user should choose the
validator that suits his needs, as dgp said before.
kennykb Ticket [1230346fff]: 2 changes [History diff]2005-11-05 02:40:43
Log in (anonymous is fine) to add a comment.