From: Tanaka Akira Date: 2013-08-09T09:42:21+09:00 Subject: [ruby-core:56463] Re: [ruby-trunk - Feature #8738] Integer#single_bit? (Actually Fixnum#single_bit? and Bignum#single_bit?) 2013/8/5 stomar (Marcus Stollsteimer) : > Issue #8738 has been updated by stomar (Marcus Stollsteimer). > Regarding the naming, I find > > 8.single_bit? # => true > > a little strange (that's 4 bits), power_of_2?/power_of_two? seem to be more to the point. I feel power_of_two? returns false for all negative numbers. But I want to determine negative powers of two. So, if power_of_two? method will be added, I'd like to add negative_power_of_two? method too. (It returns true for -1, -2, -4, ...) negative_power_of_two? can be combined with bit_length (absolute number) as n.negative_power_of_two? ? n.bit_length <= 32 : n.bit_length < 32 to determine n fits in 32 bits signed integer with two's complement format. It can be combined with bit_length (two's complement) as n.negative_power_of_two? ? n.bit_length < 53 : n.bit_length <= 53 to determine n fits in 53 bits integer with absolute number format. -- Tanaka Akira