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
#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