Sha256: 0b116369efaa04e9ea7dba29a0fb05cd603a511a3f69f769c85af3b222b14f17

Contents?: true

Size: 526 Bytes

Versions: 30

Compression:

Stored size: 526 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 != 0 && (value & (value - 1)) == 0 ? true : false
      rescue
        false
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
aruba-1.0.0 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.14 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.13 lib/aruba/contracts/is_power_of_two.rb
aruba-1.0.0.pre.alpha.5 lib/aruba/contracts/is_power_of_two.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/aruba-0.14.12/lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.12 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.11 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.10 lib/aruba/contracts/is_power_of_two.rb
aruba-1.0.0.pre.alpha.4 lib/aruba/contracts/is_power_of_two.rb
aruba-1.0.0.pre.alpha.3 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.9 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.8 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.7 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.6 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.5 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.4 lib/aruba/contracts/is_power_of_two.rb
aruba-0.14.3 lib/aruba/contracts/is_power_of_two.rb
aruba-1.0.0.pre.alpha.2 lib/aruba/contracts/is_power_of_two.rb
aruba-1.0.0.pre.alpha.1 lib/aruba/contracts/is_power_of_two.rb
aruba-win-fix-0.14.2 lib/aruba/contracts/is_power_of_two.rb