[Issue 8382] New: std.bitmanip opCmp bug or user error?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jul 12 17:56:44 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8382
Summary: std.bitmanip opCmp bug or user error?
Product: D
Version: D2
Platform: x86_64
OS/Version: Linux
Status: NEW
Severity: major
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: tracey.freitas at gmail.com
--- Comment #0 from Tracey <tracey.freitas at gmail.com> 2012-07-12 17:56:42 PDT ---
Comparing two DIFFERENT BitArrays with ">", "<", or "==" whose lengths are
greater than 8 bits always returns EQUALITY.
===========================================
The following code demonstrates my problem:
===========================================
import std.stdio, std.bitmanip;
/* Write out the BitArray, LSB->MSB */
void to_Bin(ref BitArray ba) {
foreach(i; 0..ba.length)
write(cast(ubyte)ba[i]);
writeln;
}
/* Display the result of the BitArray comparison */
void checkCmp(BitArray a, BitArray b, string name_a, string name_b) {
if(a > b) {
writeln(name_a, " > ", name_b);
}
else if (b > a) {
writeln(name_b, " > ", name_a);
}
else {
writeln(name_a, " = ", name_b);
}
}
void main() {
// BitPos: 0 1 2 3 4 5 6 7 |0 1 2 3 4 5 6 7
bool[] ba = [1, 1, 1, 1, 1, 1, 1, 1];
bool[] bb = [0, 1, 1, 1, 1, 1, 1, 1];
BitArray a; a.init(ba);
BitArray b; b.init(bb);
write("a ", cast(void[])a,": "); to_Bin(a); // output contents
write("b ", cast(void[])b,": "); to_Bin(b); // output contents
checkCmp(a, a, "a", "a"); // output comparison
checkCmp(a, b, "a", "b"); // output comparison
// PROBLEM SECTION:
// BitPos: 0 1 2 3 4 5 6 7 |0 1 2 3 4 5 6 7
bool[] bl = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
bool[] bm = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1];
BitArray l; l.init(bl);
BitArray m; m.init(bm);
write("l ", cast(void[])l,": "); to_Bin(l);
write("m ", cast(void[])m,": "); to_Bin(m);
checkCmp(l, l, "l", "l");
checkCmp(l, m, "l", "m");
}
================
which generates:
================
a [255, 0, 0, 0, 0, 0, 0, 0]: 11111111
b [254, 0, 0, 0, 0, 0, 0, 0]: 01111111
a = a
a > b
l [255, 255, 0, 0, 0, 0, 0, 0]: 1111111111111111
m [255, 253, 0, 0, 0, 0, 0, 0]: 1111111110111111
l = l
l = m <--------- WRONG
It seems unlikely that I could be using the comparison operators incorrectly in
this case. Am I missing something?
Tracey
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list