Sha256: ea72e5a09ec660c4d6dcca3156b90488385eae9953bfac16ef87ef6d59808dfa

Contents?: true

Size: 1.05 KB

Versions: 33

Compression:

Stored size: 1.05 KB

Contents

module Math
  class << self
    # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
    unless (log(2, 2) rescue false)
      def log_with_optional_base(numeric, base = Backports::Undefined)
        if base.equal?(Backports::Undefined)
          # Math.log(n) in 1.9.1 no longer accepts string arguments as it
          # did on 1.8.x, but we won't risk redefining existing behavior
          # when called with just one argument.
          log_without_optional_base(numeric)
        else
          # Math.log(n, b) in 1.9.1 does not accept string arguments:
          raise TypeError, "can't convert String into Float" if numeric.is_a?(String) || base.is_a?(String)
          log_without_optional_base(numeric) / log_without_optional_base(base)
        end
      end
      Backports.alias_method_chain self, :log, :optional_base
    end

    # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/Math.html]
    def log2(numeric)
      log(numeric, 2)
    end unless method_defined? :log2
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
backports-3.0.2 lib/backports/1.9.1/math.rb
backports-3.0.1 lib/backports/1.9.1/math.rb
backports-3.0.0 lib/backports/1.9.1/math.rb
backports-2.8.2 lib/backports/1.9.1/math.rb
backports-2.8.1 lib/backports/1.9.1/math.rb
backports-2.8.0 lib/backports/1.9.1/math.rb
backports-2.7.1 lib/backports/1.9.1/math.rb
backports-2.7.0 lib/backports/1.9.1/math.rb
backports-2.6.7 lib/backports/1.9.1/math.rb
backports-2.6.6 lib/backports/1.9.1/math.rb
backports-2.6.5 lib/backports/1.9.1/math.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/backports-2.6.4/lib/backports/1.9.1/math.rb
backports-2.6.4 lib/backports/1.9.1/math.rb
backports-2.6.3 lib/backports/1.9.1/math.rb
backports-2.6.2 lib/backports/1.9.1/math.rb
backports-2.6.1 lib/backports/1.9.1/math.rb
backports-2.6.0 lib/backports/1.9.1/math.rb
backports-2.5.3 lib/backports/1.9.1/math.rb
backports-2.5.2 lib/backports/1.9.1/math.rb
backports-2.5.1 lib/backports/1.9.1/math.rb