value range propagation for _bitwise_ OR

"Jérôme M. Berger" jeberger at free.fr
Mon Apr 12 10:39:57 PDT 2010


Ali Çehreli wrote:
> Jérôme M. Berger wrote:
>> Ali Çehreli wrote:
>>> � wrote:
>>>
>>>> The idea is to build a value that is  between minA and maxA and will
>>>> set as many bits as possible when or'ed with maxB:
>>> The assumption that maxB would be the value that produces the maximum
>>> a|b is not correct. A lower valued b may fill more gaps in the bit
>>> representation of what is calculated from min_a and max_a.
>>>
>>> Your function failed for me with the following values:
>>>
>>>            min_a 00000000000000000000000011001000 000000c8        200
>>>            max_a 00000000000000000000001100001111 0000030f        783
>>>            min_b 00000000000000000000000001000101 00000045         69
>>>            max_b 00000000000000000000001001100001 00000261        609
>>>       calculated 00000000000000000000001001100101 00000265        613
>>> WRONG! empirical 00000000000000000000001111111111 000003ff       1023
>>>        emp_max_a 00000000000000000000000110011110 0000019e        414
>>>        emp_max_b 00000000000000000000001001100001 00000261        609
>>>
>>> Please see my test code elsewhere in the same thread: :)
>>>
>>>
> http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=108851
> 
>>>
>>     The "calculated" value above obviously was not computed with my
>> function!
> 
> My mistake: It was your function but the highbit() that I used was not
> correct. The one I used was returning the *value* of the highest bit.
> 
>> Since the return value from my function includes maxA and
>> maxB, at least all bits that are set in either of those should be
>> set in the output.
>>
>>     I've run my code with those input and the result is 3ff as
>> expected... (See attached source file).
> 
> Perhaps my test code is wrong; but I can't find my error. :/
> 
> Your function reports 0b_111 for these set of values:
> 
>         min_a = 5;
>         max_a = 6;
>         min_b = 4;
>         max_b = 4;
> 
> But the maximum value of a|b is 6.
> 
	Yes, like I said with my code, it is conservative. It will give the
optimal result for over 99% of the cases but give a slightly higher
value for the rest. I'll post a new version that's 100% precise in a
few minutes.

		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/eff3e6e9/attachment.pgp>


More information about the Digitalmars-d mailing list