RFR: 8346914: UB issue in scalbnA
Fredrik Bredberg
fbredberg at openjdk.org
Thu Jun 5 15:26:49 UTC 2025
On Thu, 5 Jun 2025 13:54:49 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:
>> I'm suprised that is even valid TBH. It strikes me as a numerical oxymoron.
>
>>"If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type). [ Note: In a two’s complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). —end note ]
>
> So this is OK.
The hard part for me is that when I see `-54u` , I need to make sure it's return type is `unsigned`, which is not immediately obvious to me. Reading what the standard say about the built-in unary minus operator I find: _"The type of the result is the type of the promoted type of expression."_ Which means that the return type of `-54u` really is `unsigned`. But I do agree with David, it looks like a numerical oxymoron.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25656#discussion_r2129118383
More information about the hotspot-dev
mailing list