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

nth_bit and friends are broken

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 9
    • hotspot
    • None
    • gc
    • b115

      The macros lack brackets around n:
      #define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n))
      #define right_n_bits(n) (nth_bit(n) - 1)
      #define left_n_bits(n) (right_n_bits(n) << (n >= BitsPerWord ? 0 : (BitsPerWord - n)))

      So, some esoteric usages produce the wrong result.

      Examples from a 64 bit JVM,
      nth_bit(true ? 32 : 64) returns 0x20 instead of 0x0000000100000000
      nth_bit(1|2) returns 0x0 instead of 0x8

            stefank Stefan Karlsson
            stefank Stefan Karlsson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: