Tk Library Source Code

View Ticket
Login
Ticket UUID: 1093414
Title: bitwise AND, OR and XOR for tcllib bignum
Type: Bug Version: None
Submitter: aakhter Created on: 2004-12-30 19:20:52
Subsystem: math Assigned To: andreas_kupries
Priority: 7 High Severity:
Status: Closed Last Modified: 2005-01-11 05:24:21
Resolution: Accepted Closed By: andreas_kupries
    Closed on: 2005-01-10 22:24:21
Description:
bitwise AND, OR and XOR for tcllib bignum
User Comments: andreas_kupries added on 2005-01-11 05:24:21:
Logged In: YES 
user_id=75003

Integrated, with a minimal testsuite, and modified docs, the
latter to make the limitation to positive numbers clear.

andreas_kupries added on 2005-01-08 01:22:10:
Logged In: YES 
user_id=75003

Aamer, some questions and notes on this code.

Note: In the future please use 'diff -u'  to generate
patches. The result is much more human readable, and also
easier to apply.

Questions:

(1) How does your code behave when negative numbers are
given to the commands ? The docs makes no mention of
negatives being special, but when I look at the code it
seems to me that the sign of the inputs is completely
ignored, and the result is always positive. The question is
if that is intentional, if you don't care about negative
inputs, or something else ? In case negatives are not
handled, intentionally, the docs should state this, to make
the restriction clear. Otherwise we would get bug reports
the first time someone tries to use negatives.

(2) Do you have a testsuite for the operations ? That is
really important IMHO.

More musings:

Due to a talk on the Tcler's chat with Kevin, who is working
on a long-term thing about bignum ints in the Tcl core we
also have some definitions which should allow the handling
of negative numbers in the bitops. IOW instead of
documenting the restriction we could try and extend the code
to handle negative numbers as well. See below:

Base definition: bitnot A == (-A)-1  [Two's complement].

And then various laws, like DeMorgan to handle negatives:

A & B ==
    ~(~A | ~B), for A, B < 0.
    The | is given positive numbers, and is thus trivial to do.
    A & B, for A, B >=0
    A & ~C, for A >=0, B < 0. where C = ~B, and
    bitwise expansion is possible.

A | B, A ^ B have similar rules.

aakhter added on 2004-12-31 02:20:52:

File Added - 113915: bignum-bitops2.diff

Attachments: