Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
8288414: Long::compress/expand samples are not correct
Browse files Browse the repository at this point in the history
Reviewed-by: alanb
  • Loading branch information
Paul Sandoz committed Jun 15, 2022
1 parent f3b1f60 commit 395aea3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/java.base/share/classes/java/lang/Long.java
Expand Up @@ -1926,7 +1926,7 @@ public static long reverse(long i) {
* value:
* {@snippet lang="java" :
* // Compressing drink to food
* compress(0xCAFEBABE, 0xFF00FFF0) == 0xCABAB
* compress(0xCAFEBABEL, 0xFF00FFF0L) == 0xCABABL
* }
* Starting from the least significant hexadecimal digit at position 0
* from the right, the mask {@code 0xFF00FFF0} selects hexadecimal digits
Expand All @@ -1938,16 +1938,16 @@ public static long reverse(long i) {
* understand the behaviour of {@code compress}:
* {@snippet lang="java" :
* // Returns 1 if the bit at position n is one
* compress(x, 1 << n) == (x >> n & 1)
* compress(x, 1L << n) == (x >> n & 1)
*
* // Logical shift right
* compress(x, -1 << n) == x >>> n
* compress(x, -1L << n) == x >>> n
*
* // Any bits not covered by the mask are ignored
* compress(x, m) == compress(x & m, m)
*
* // Compressing a value by itself
* compress(m, m) == (m == -1 || m == 0) ? m : (1 << bitCount(m)) - 1
* compress(m, m) == (m == -1 || m == 0) ? m : (1L << bitCount(m)) - 1
*
* // Expanding then compressing with the same mask
* compress(expand(x, m), m) == x & compress(m, m)
Expand All @@ -1969,7 +1969,7 @@ public static long reverse(long i) {
* }
*
* // Separate the sheep from the goats
* sag(0xCAFEBABE, 0xFF00FFF0) == 0xCABABFEE
* sag(0x00000000_CAFEBABEL, 0xFFFFFFFF_FF00FFF0L) == 0x00000000_CABABFEEL
* }
*
* @param i the value whose bits are to be compressed
Expand Down Expand Up @@ -2018,7 +2018,7 @@ public static long compress(long i, long mask) {
* Consider the simple case of expanding the digits of a hexadecimal
* value:
* {@snippet lang="java" :
* expand(0x0000CABAB, 0xFF00FFF0) == 0xCA00BAB0
* expand(0x0000CABABL, 0xFF00FFF0L) == 0xCA00BAB0L
* }
* Starting from the least significant hexadecimal digit at position 0
* from the right, the mask {@code 0xFF00FFF0} selects the first five
Expand All @@ -2029,13 +2029,13 @@ public static long compress(long i, long mask) {
* understand the behaviour of {@code expand}:
* {@snippet lang="java" :
* // Logically shift right the bit at position 0
* expand(x, 1 << n) == (x & 1) << n
* expand(x, 1L << n) == (x & 1) << n
*
* // Logically shift right
* expand(x, -1 << n) == x << n
* expand(x, -1L << n) == x << n
*
* // Expanding all bits returns the mask
* expand(-1, m) == m
* expand(-1L, m) == m
*
* // Any bits not covered by the mask are ignored
* expand(x, m) == expand(x, m) & m
Expand All @@ -2049,7 +2049,7 @@ public static long compress(long i, long mask) {
* {@snippet lang="java" :
* long select(long i, long n) {
* // the one-bit in i (the mask) with index n
* long nthBit = Long.expand(1 << n, i);
* long nthBit = Long.expand(1L << n, i);
* // the bit position of the one-bit with index n
* return Long.numberOfTrailingZeros(nthBit);
* }
Expand Down

1 comment on commit 395aea3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.