|
2005-12-12
| ||
| 18:38 | • Ticket [1241572fff] expr blind spot at corner of 32/64 bit integers status... artifact: 8e9a85e96a user: rmax | |
| 18:38 | • Add attachment tcl-abs.patch to ticket [1241572fff] artifact: 7085940e42 user: rmax | |
| 18:38 | • Closed ticket [1241572fff]: expr blind spot at corner of 32/64 bit integers</i... artifact: 632f38091c user: rmax | |
| 17:38 | • Ticket [1241572fff]: 4 changes artifact: 426a77ab2a user: nobody | |
|
2005-12-10
| ||
| 01:13 | • Add attachment tcl-abs.patch to ticket [1241572fff] artifact: eafb67e55a user: rmax | |
| 01:13 | • Ticket [1241572fff] expr blind spot at corner of 32/64 bit integers status... artifact: 8ed4d683b7 user: rmax | |
| 00:39 | • Ticket [1241572fff]: 1 change artifact: 1a818dff66 user: rmax | |
| 00:32 | • Open ticket [1241572fff]. artifact: ffb154fd37 user: rmax | |
|
2005-08-06
| ||
| 02:24 | • Closed ticket [1241572fff]. artifact: 31a6d8f197 user: kennykb | |
|
2005-07-21
| ||
| 00:20 | • Ticket [1241572fff]: 1 change artifact: a5885f4afb user: hobbs | |
|
2005-07-20
| ||
| 21:05 | • Ticket [1241572fff]: 4 changes artifact: 1c7a0e4709 user: dkf | |
| 13:52 | • New ticket [1241572fff]. artifact: c3e94555a4 user: nobody | |
[expr] blind spot at corner of 32/64 bit integers
Closed / Fixed1241572fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-07-20 13:52:06
% set x -2147483647; expr {abs($x)}
2147483647
% set x -2147483648; expr {abs($x)}
integer value too large to represent
% set x -2147483649; expr {abs($x)}
2147483649
This is a practical problem as we use -2147483648
(0x80000000, MIN_INT) to express missing data.
Seen in 8.4.1 and 8.5a2 Tclkit, Windows XP and Linux.
[email protected]
dkfplain2005-07-20 21:05:29
Logged In: YES user_id=79902 Problem is it that it hits the "FIXME" case in ExprAbsFunc (in tclBasic.c in the HEAD.)
hobbs Ticket [1241572fff]: 1 change
[History diff]2005-07-21 00:20:25
kennykbplain2005-08-06 02:24:29
Logged In: YES
user_id=99768
Right you are. Although in 8.4.11, you have to do
expr {int(-2147483648)} to tickle the bug. Anyway, abs()
is fixed.
rmaxplain2005-12-10 00:32:22
Logged In: YES user_id=124643 This fix depends on implementation defined behaviour of the compiler and fails with gcc 4.1.0. What happens is, that the compiler decides that the negation of a negative number can never have a negative result, and so it optimizes away the special case for INT_MIN as dead code. There are two solutions for this: either rewriting the code so that it doesn't depend on the assumption that -MIN_INT == MIN_INT, or use the -fwrapv parameter to gcc, so that it guarantees the wrapping behaviour of integers. See also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25329
rmax Ticket [1241572fff]: 1 change
[History diff]2005-12-10 00:39:50
rmaxplain2005-12-10 01:13:03
File Added - 159278: tcl-abs.patch
nobodyplain2005-12-12 17:38:51
Logged In: NO Hmm - my patch fixes 32bit platform, but it breaks 64bit :( How about using MIN_INT from limits.h for checking this special case, and providing compatibility definitions for platforms that don't have limits.h?
rmaxplain2005-12-12 18:38:40
Logged In: YES user_id=124643 I just committed the attached patch to the 8.4 branch. It assumes that MIN_LONG is defined by one of the headers that are being included already. If there is any platform where this isn't true, a compatibility definition needs to be added.
rmaxplain2005-12-12 18:38:42
File Added - 159527: tcl-abs.patch
Log in (anonymous is fine) to add a comment.
Attachments:
- tcl-abs.patch [download] added by rmax on 2005-12-12 18:38:41. [details]