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 But the documentation is not clear about this, it should be specified... ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/21323#discussion_r1794189722