Sha256: e776d4839787d70b6602497f5d137d53ca9d88ceaedd76ccab371522a6ac1d99
Contents?: true
Size: 531 Bytes
Versions: 10
Compression:
Stored size: 531 Bytes
Contents
require "aruba/aruba_path" # Aruba module Aruba # Contracts module Contracts # Is value power of two class IsPowerOfTwo # Check value # # @param [Integer] value # The value to be checked def self.valid?(value) # explanation for algorithm can be found here: # http://www.exploringbinary.com/ten-ways-to-check-if-an-integer-is-a-power-of-two-in-c/ value.positive? && (value & (value - 1)).zero? rescue StandardError false end end end end
Version data entries
10 entries across 10 versions & 3 rubygems