Hi,

this is my function which I'm using to determine the bit width of
a given value.

int getBWidth( long long constValue )
{
  int bWidth = 0;
  for ( int n = 64; n >= 1; n-- )
    if ( ( constValue >= -pow( (float) 2, n - 1 ) ) &&
         ( constValue <= pow( (float) 2, n - 1 ) - 1 ) )
      bWidth = n;
    else
      return bWidth;
  return bWidth;
}


This function works fine for small arguments. But for larger
long long values the results deviate, e.g.
passing 4294967295 ( 2^32 - 1 ) as signed long long argument should result
in a return value of bWidth=33 while argument 4294967296 should return
the value 34. 
However, the function returns for both values the value 34. After playing
around with some function arguments I figured out that the threshold
among 33 and 34 bits is the value 4294967168.

So, my question is where the deviation between 4294967296 and 
4294967168 comes from?

Thank you.

Chris
_______________________________________________
Help-gplusplus mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to