value range propagation for _bitwise_ OR

Ali Çehreli acehreli at yahoo.com
Sun Apr 11 16:31:30 PDT 2010


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.

Ali



More information about the Digitalmars-d mailing list