value range propagation for _bitwise_ OR
"Jérôme M. Berger"
jeberger at free.fr
Mon Apr 12 10:56:23 PDT 2010
Here's a fast 100% precise solution:
==============================8<------------------------------
uint32_t maxOr (uint32_t minA, uint32_t minB,
uint32_t maxA, uint32_t maxB)
{
assert (minA <= maxA);
assert (minB <= maxB);
if (maxA == 0) return maxB;
if (maxB == 0) return maxA;
uint32_t a = maxA ^ minA;
if (a != 0) {
a = ((1 << (highbit (a)+1)) - 1) & maxA & maxB;
if (a != 0)
a = (1 << highbit (a)) - 1;
}
uint32_t b = maxB ^ minB;
if (b != 0) {
b = ((1 << (highbit (b)+1)) - 1) & maxA & maxB;
if (b != 0)
b = (1 << highbit (b)) - 1;
}
return maxA|maxB|a|b;
}
------------------------------>8==============================
Jerome
--
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100412/8adb4ca4/attachment.pgp>
More information about the Digitalmars-d
mailing list