Tk Library Source Code

View Ticket
Login
Ticket UUID: 1098051
Title: bignum::rshift is wrong for negative inputs.
Type: Bug Version: None
Submitter: andreas_kupries Created on: 2005-01-07 18:14:30
Subsystem: math Assigned To: arjenmarkus
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2006-04-25 19:31:52
Resolution: None Closed By: arjenmarkus
    Closed on: 2006-04-25 12:31:52
Description:
Test cases to consider:

[10:04]kbkOh, by the way, >> is wrong as well.
[10:05]akuAre you talking about bignum::rshift ?
[10:05]kbkUhm, yeah. -1>>1 is -1, not 0; -3>>1 is -2,
not -1.
[10:06]akuWell, rshift is not tested by the bignum
testsuite.
[10:06]kbkWell, I suppose that I've just proposed a
couple of tests, then. 
[10:07]akuYep
[10:08]akuI will cut&paste this into a bug report

And a solution, by Kevin:

[10:08]kbkFixing that one is: A>>B = ~(~A>>B) =
-((-A-1)>>B)-1

Note: ~A is defined as (-A)-1 (Infinite precision
two-complement).

The general context is a talk on the chat about bignums
in Tcl (core-level), something Kevin is working on, and
for complete seamlessness he has to impl. all bitops,
i.e. &, |. ^. Through this we also looked at the tcllib
bignum code in this area. Especially as there is a RFE
pending for more bitops as well.

[10:11]akuWe might have to look at the
set/clear/test-bit operators as well I guess.
[10:12]kbkWell, for tcllib's bignums, we don't have
to make them algebraically consistent with 2-s comp
ints, because they can't appear in [expr].
User Comments: arjenmarkus added on 2006-04-25 19:31:52:
Logged In: YES 
user_id=400048

This one is solved

arjenmarkus added on 2006-02-13 22:20:21:
Logged In: YES 
user_id=400048

I made a correction to the rshift proc (not the rshiftBits 
proc that it uses, as that is used in more than one place). 
The idea for the test cases is to reproduce the results of 
Tcl's expr for those integers that can be represented by 
ordinary integers and by bignum.

andreas_kupries added on 2006-01-31 11:21:31:
Logged In: YES 
user_id=75003

Rely on the ordinary operations how ?
They do work correctly assuming that the Tcl integers are
limited-precision (32 or 64 bit). In 8.5 they are themselves
extended for bignums. ... That may mean that you can use 8.5
regular ops to determine what results the tests should
expect. Kevin might be able to help you with that.

arjenmarkus added on 2006-01-30 20:34:03:
Logged In: YES 
user_id=400048

I ought to add the proposed tests (mind you: bit operations 
are not my cup-of-tea - I will need some help on the 
correct outcome or can I rely on the bit operations in Tcl 
for ordinary integers?

andreas_kupries added on 2006-01-29 16:16:30:
Logged In: YES 
user_id=75003

Is this report still relevant ?

arjenmarkus added on 2005-01-13 16:43:14:
Logged In: YES 
user_id=400048

I have asked Salvatore Sanfilippo, who wrote this package to
look into these problems