Skip to content
Tcl Source Code View Ticket
Login

View Ticket

round() doesn't support numbers larger than 31 bits

Closed / Fixed908375ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 22 years ago
Descriptionplain2004-03-02 15:39:49
This was just reported by one of our users today. It
seems that round() doesn't seem to handle numbers
larger than 31 bits:

godel:49> /tmp/hlavana/tcltk/bin/tclsh8.4 
% info patch
8.4.6
% expr round( 2147483647.1 )
2147483647
% expr round( 2147483648.1 )
integer value too large to represent
% expr {2147483648+1}
2147483649
% exit
godel:50> 

If this is a bug, would it be possible to get it fixed
for tcl8.4.6 or is it too late now?
dkfplain2004-03-02 23:40:16
Logged In: YES 
user_id=79902

It's too late for 8.4.6 as we've already got a release
candidate out for distribution testing (or whatever the
proper term is.)  With any change we'd have to start the
whole release process over again.  Sorry.  :^(  I'll make
this a high prio fix for 8.5a1 though and backport to the
8.4 branch.
hemanglavanaplain2004-03-05 22:23:02
Logged In: YES 
user_id=81875

The current workaround for this issue is to use the wide()
and add 0.5 to the number for rounding:

hlavana-u5:81> tclsh
% expr wide(2147483648.1)
2147483648
% expr wide(2147483648.9)  
2147483648
% expr wide(2147483648.9+0.5)
2147483649
% expr wide(2147483648.1+0.5)
2147483648
%
dkfplain2004-03-30 05:04:12
File Added - 81829: wideRound.patch

Logged In: YES 
user_id=79902

Try this patch.  The downside is that the result from
round() will normally be a wide now.
hemanglavanaplain2004-03-31 03:07:27
Logged In: YES 
user_id=81875

The patch seems to work fine:

godel:148> /tmp/hlavana/tcltk/bin/tclsh8.5 
% info patch
8.5a2
% expr round( 2147483648.1 )
2147483648
% expr round( 2147483648.9 )
2147483649
% exit
godel:149> 

I don't see the result of round() as wide to be an issue.

-- thanks
dkfplain2004-05-30 19:36:49
Logged In: YES 
user_id=79902

Please review this and apply the patch if you think it is
not too semantics-damaging.
msoferplain2004-07-03 04:53:57
File Added - 92706: wideRound2.patch

Logged In: YES 
user_id=148712

I do not like coercing all results of 'round' to wide;
attached a patch that only does this when necessary. Your
turn :)
dkfplain2004-07-03 05:01:37
Logged In: YES 
user_id=79902

I don't know what answer anyone expects out of round() in
the first place. :/

So long as we have a consistent story, I don't really care.
dkfplain2004-07-03 05:13:21
Logged In: YES 
user_id=79902

I suppose if we restrict ourselves to just producing wides
in the case where we would have failed previously, we'll be
monotonically improving things...
msoferplain2004-07-04 04:36:58
Logged In: YES 
user_id=148712

Fixed in HEAD; should I backport to core-8-4-branch?
msoferplain2004-07-04 05:13:29
Logged In: YES 
user_id=148712

Backported.
Log in (anonymous is fine) to add a comment.

Attachments: