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

Fixnum#bit_length always returns 64 for negative number #3829

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

Comments

Projects
None yet
2 participants
@jkr2255

jkr2255 commented Apr 26, 2016

According to CRuby manual, Fixnum#bit_length returns "the bit position of the highest bit which is different to the sign bit". In other words, check 0 bit position for negative numbers.

In JRuby implementation it returns 64 - Long.numberOfLeadingZeros(value).

Long.numberOfLeadingZeros(value) returns 0 if value is negative, so the value is fixed to 64 in the cases.

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] on CentOS 7 x64
  • JRuby 9.0.5.0 (x64) on Windows7 x64

Expected Behavior

p (-1).bit_length # => 0

Actual Behavior

p (-1).bit_length # => 64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment