New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bignum#bit_length is missing #3827

Closed
jkr2255 opened this Issue Apr 26, 2016 · 0 comments

Comments

Projects
None yet
2 participants
@jkr2255

jkr2255 commented Apr 26, 2016

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment