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

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/contracts/is_power_of_two.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/contracts/is_power_of_two.rb
aruba-2.2.0 lib/aruba/contracts/is_power_of_two.rb
aruba-2.1.0 lib/aruba/contracts/is_power_of_two.rb
aruba-2.0.1 lib/aruba/contracts/is_power_of_two.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/aruba-2.0.0/lib/aruba/contracts/is_power_of_two.rb
aruba-2.0.0 lib/aruba/contracts/is_power_of_two.rb
aruba-1.1.2 lib/aruba/contracts/is_power_of_two.rb
aruba-1.1.1 lib/aruba/contracts/is_power_of_two.rb
aruba-1.1.0 lib/aruba/contracts/is_power_of_two.rb