Skip to content

Bignum#bit_length is missing #3827

@jkr2255

Description

@jkr2255

In CRuby >= 2.1, both Fixnum and Bignum have #bit_length method. (Reference of Ruby 2.1 Bignum)

On the other hand, JRuby 9.0.x implements only Fixnum#bit_length, Bignum#bit_length is not implemented.

Java's BigInteger has bitLength method, so it can be polyfilled, but lacking CRuby's method is a problem.

# Polyfill code
class Bignum
  def bit_length
    to_java.bitLength
  end
end

Environment

  • jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa OpenJDK 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [linux-amd64]
  • JRuby 9.0.5.0 (x64) on Windows7 x64

Expected Behavior

p (2**1000).respond_to?(:bit_length) # => true
p (2**1000).bit_length # => 1001

Actual Behavior

p (2**1000).respond_to?(:bit_length) # => false
p (2**1000).bit_length # => raises NoMethodError

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions