[Issue 9061] BigInt | BigInt, BigInt & int

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 8 07:46:33 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=9061



--- Comment #9 from Simen Kjaeraas <simen.kjaras at gmail.com> 2013-11-08 07:46:26 PST ---
So that's all decided, then.

The remaining problem is, as stated above, uints. 

As we all know, uints don't have sign bits. This means there's no sign to
extend. Hence, we're back to the described problem, only slightly different.

In this case, the result should be padded with 1s:

import std.bigint : BigInt;

void main() {
    BigInt a = "0xB16_B16_B16_B16_B16_B16_B96_B16_B16";
    uint b = 0x8000_0000;
    BigInt c = a & ~b; // Unset bit 31
    assert(c == BigInt("0xB16_B16_B16_B16_B16_B16_B16_B16_B16");
}

In this case, the result should be padded with 0s:

import std.bigint : BigInt;

void main() {
    BigInt a = "0xB16_B16_B16_B16_B16_B16_B96_B16_B16";
    uint b = 0x8000_0000;
    BigInt c = a & b; // Separate bit 31
    assert(c == 0x8000_0000);
}


I'm starting to think the best solution is to simply disallow bitwise
operations that involve both a uint and a BigInt, and this is what I'll
implement, unless a solution is presented (that is different from 'pad with
0s', 'pad with 1s', 'pad with highest bit' and 'pad with inverse of highest
bit', *and* sensible).

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list