diff options
Diffstat (limited to 'spec/rubyspec/core/bignum/bit_length_spec.rb')
-rw-r--r-- | spec/rubyspec/core/bignum/bit_length_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/rubyspec/core/bignum/bit_length_spec.rb b/spec/rubyspec/core/bignum/bit_length_spec.rb new file mode 100644 index 0000000000..1c4c518345 --- /dev/null +++ b/spec/rubyspec/core/bignum/bit_length_spec.rb @@ -0,0 +1,33 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +describe "Bignum#bit_length" do + it "returns the position of the leftmost bit of a positive number" do + (2**1000-1).bit_length.should == 1000 + (2**1000).bit_length.should == 1001 + (2**1000+1).bit_length.should == 1001 + + (2**10000-1).bit_length.should == 10000 + (2**10000).bit_length.should == 10001 + (2**10000+1).bit_length.should == 10001 + + (1 << 100).bit_length.should == 101 + (1 << 100).succ.bit_length.should == 101 + (1 << 100).pred.bit_length.should == 100 + (1 << 10000).bit_length.should == 10001 + end + + it "returns the position of the leftmost 0 bit of a negative number" do + (-2**10000-1).bit_length.should == 10001 + (-2**10000).bit_length.should == 10000 + (-2**10000+1).bit_length.should == 10000 + + (-2**1000-1).bit_length.should == 1001 + (-2**1000).bit_length.should == 1000 + (-2**1000+1).bit_length.should == 1000 + + ((-1 << 100)-1).bit_length.should == 101 + ((-1 << 100)-1).succ.bit_length.should == 100 + ((-1 << 100)-1).pred.bit_length.should == 101 + ((-1 << 10000)-1).bit_length.should == 10001 + end +end |