RFR: 8341470: BigDecimal.stripTrailingZeros() optimization [v12]
Raffaello Giulietti
rgiulietti at openjdk.org
Wed Oct 9 21:14:14 UTC 2024
On Wed, 9 Oct 2024 20:47:25 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> 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...
The class Javadoc mentions, in at least two places, that the two's complement representation conceptually has an infinite number of leading virtual sign bits.
Once this point is clear, IMO the method's own Javadoc is then clear in turn. Maybe it could be improved as in "the bits that differ _in value_ from its sign bit". (Changing the spec requires another process and another, separate issue, but it can be done if needed.)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21323#discussion_r1794234926
More information about the core-libs-dev
mailing list