On Wed, 9 Oct 2024 20:19:39 GMT, Raffaello Giulietti <rgiulie...@openjdk.org> 
wrote:

>> @rgiulietti I think I just found a problem much more serious than a simple 
>> optimization, I'm afraid the semantics of `BigInteger.bitCount()` is 
>> ill-defined, although it seems absurd to me that no one has noticed it so 
>> far...
>
> What's wrong with the semantics? In my understanding, it should count the 
> ones for non-negative values and the zeros for negative values, where 
> non-negative values have an infinite prefix of zero bits and negative values 
> have an infinite prefix of one bits in two's complement representation.
> 
> Note that this is different from `[Long|Integer].bitCount()`, which consider 
> their arguments as finite width unsigned bit strings.

@rgiulietti At least for me, the expression "the bits that differ from its sign 
bit" is misleading, it seems to implicitly imply that he is talking about the 
1s bits which are not sign bits, while it means the bits whose value differs 
from the value of the sign bits...

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21323#discussion_r1794205023

Reply via email to