|
2005-08-24
| ||
| 01:37 | • Closed ticket [1228275fff]: expr cannot cope with wideInt results on 32bit UNI... artifact: 6d49dab446 user: mdejong | |
|
2005-06-30
| ||
| 04:14 | • Ticket [1228275fff]: 4 changes artifact: 8a50da5e85 user: mdejong | |
|
2005-06-27
| ||
| 21:13 | • Ticket [1228275fff]: 4 changes artifact: 49122ebd77 user: matzek | |
| 21:03 | • Ticket [1228275fff]: 4 changes artifact: 166b6dbf97 user: dkf | |
| 13:55 | • New ticket [1228275fff]. artifact: ac7b556454 user: matzek | |
[expr] cannot cope with wideInt results on 32bit UNIX
Closed / Invalid1228275fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-06-27 13:55:26
Hi *,
although I haven't found much documentation about this
[expr] behavior, Welch et al. are writing: "The result
of an arithmetic operation is [...] a wide integer if
at least one of the operands is a wide integer, and a
normal integer otherwise." And the manual of [expr]
says: "wide(arg): Converts arg to an integer value at
least 64-bits wide (by sign-extension if arg is a
32-bit number) if it is not one already."
I now have two values, both fitting into a signed
integer, which would need a wide integer when summed
up. But I am somehow unable to get the right result:
$ tcl-8.4.9/bin/tclsh8.4
% expr {(1<<31)+1}
-2147483647
% expr {(1<<31)+wide(1)}
-2147483647
% expr {wide(1<<31)+1}
-2147483647
% expr {wide((1<<31))+1}
-2147483647
% expr {wide((1<<31)+1)}
-2147483647
On a 64bit system and compiled with --enable-64bit, I
get the right result, right from the start:
$ tcl-8.4.9/bin/tclsh8.4
% expr {(1<<31)+1}
2147483649
-- Matthias Kraft
dkfplain2005-06-27 21:03:47
Logged In: YES user_id=79902 The problem is that it is the << operation that is doing the wrong thing with the signs, and not the operations around it. On a 32-bit system: % expr (wide(1)<<31)+1 2147483649
matzekplain2005-06-27 21:13:28
Logged In: YES user_id=330806 Oh, yes ... well that solves my problem, feel free to close then.
mdejongplain2005-06-30 04:14:14
Logged In: YES
user_id=90858
I think this is what you meant to do. 1<<31 is a negative
number.
% expr {(1<<31)-1}
2147483647
% expr {wide(1<<31)-1}
-2147483649
mdejong Closed ticket [1228275fff].
[History diff]2005-08-24 01:37:16
Log in (anonymous is fine) to add a comment.