| Ticket UUID: | 1085562 | |||
| Title: | math::bignum::testbit fails | |||
| Type: | Bug | Version: | None | |
| Submitter: | aubinroy | Created on: | 2004-12-15 03:27:34 | |
| Subsystem: | math | Assigned To: | andreas_kupries | |
| Priority: | 5 Medium | Severity: | ||
| Status: | Closed | Last Modified: | 2006-01-31 11:37:26 | |
| Resolution: | Fixed | Closed By: | andreas_kupries | |
| Closed on: | 2006-01-31 04:37:26 | |||
| Description: |
I want to report a bug in ::math::bignum::testbit.
In the documentation I got (ActiveTCL help file, version
8.4.9.0), it says:
::math::bignum::testbit bignum bit
Return true if the bit at the bit position of bignum is on,
otherwise false is returned. If bit is out of range, it is
considered as set to zero.
However, if I use this test bit on a "bignum" for which a
bit has NOT been set yet, it fails miserably.
Here is the TCL code to induce the bug and the error
message reported:
(bin) 3 % package require math::bignum
3.0
(bin) 4 % set z [::math::bignum::fromstr "3220"]
bignum 0 3220
(bin) 5 % ::math::bignum::testbit $z 23
can't use empty string as operand of "&"
(bin) 6 %
However, if a bit has previously been set which is equal
or greater than the bit tested, then the error message is
NOT reported.
(bin) 8 % ::math::bignum::setbit z 24
bignum 0 3220 256
(bin) 9 % ::math::bignum::testbit $z 23
0
(bin) 10 %
By comparison with the other functions and
some "analysis", I have concluded that 2 lines are in the
wrong order.
As it stands now, the function reads as:
# Test the bit 'n' of 'z'. Returns true if the bit is set.
proc ::math::bignum::testbit {z n} {
set atom [expr {$n / $::math::bignum::atombits}]
######## Next 2 lines in wrong order
if {$atom >= [llength $z]} {return 0}
incr atom 2
########
set mask [expr {1 << ($n &
($::math::bignum::atombits-1))}]
expr {([lindex $z $atom] & $mask) != 0}
}
when it should read as:
# Test the bit 'n' of 'z'. Returns true if the bit is set.
proc ::math::bignum::testbit {z n} {
set atom [expr {$n / $::math::bignum::atombits}]
######## Next 2 lines identical to other functions
incr atom 2
if {$atom >= [llength $z]} {return 0}
########
set mask [expr {1 << ($n &
($::math::bignum::atombits-1))}]
expr {([lindex $z $atom] & $mask) != 0}
}
| |||
| User Comments: |
andreas_kupries added on 2006-01-31 11:37:26:
Logged In: YES user_id=75003 Extended testsuite and fixed in CVS head now. Thank you for your patience. aubinroy added on 2006-01-31 02:45:03: Logged In: YES user_id=1178514 I am the one that filed this bug a LONG time ago. It requires only a simple fix: swap two lines in the testbit routine. I am still relying on my workaround since the time that bug was filed. From my point of view, this has still to be fixed. Best regards, ---/aubin/--- andreas_kupries added on 2006-01-29 16:17:08: Logged In: YES user_id=75003 Is this still current ? Should it be re-assigned to sarnold75 ? | |||
Home
Blog
Docs
Downloads
Tickets
Timeline
Branches
Tags
Wiki