Sha256: b015ef4a6138e5bb378335dd312a7459c755d2724701275c9a136f693917a15b

Contents?: true

Size: 241 Bytes

Versions: 2

Compression:

Stored size: 241 Bytes

Contents

class << Math
  def log2(n); log(n) / log(2); end
end

class Integer
  def power_of_2?
    Math::log2(self).to_i == Math::log2(self)
  end

  def closest_power_of_2
    self.upto(32) do |i|
      return i if i.power_of_2?
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
relevance_ipaddress-0.5.0 lib/ipaddress/extensions/extensions.rb
ipaddress-0.5.0 lib/ipaddress/extensions/extensions.rb