Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8288414

Long::compress/expand samples are not correct

XMLWordPrintable

    • b19
    • b28

        The samples provided in java doc https://download.java.net/java/early_access/jdk19/docs/api/java.base/java/lang/Long.html#compress(long,long) looks not resulting as it states.

        For example :

        Consider the simple case of compressing the digits of a hexadecimal value:

        // Compressing drink to food
        compress(0xCAFEBABE, 0xFF00FFF0) == 0xCABAB

        The result is if(Long.compress(0xCAFEBABE, 0xFF00FFF0) == 0xCABAB){}
        different.

        And same for subsequent samples in case of Long

        // Returns 1 if the bit at position n is one
        compress(x, 1 << n) == (x >> n & 1)

        // Logical shift right
        compress(x, -1 << n) == x >>> n
        ....


        But these samples works as stated in case of Integer.





              psandoz Paul Sandoz
              kganapureddy Krushnareddy Ganapureddy
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: