Permalink
Browse files

Merge pull request #14 from dgrijalva/master

Fix for encoding of negative bignums
  • Loading branch information...
2 parents 727ee16 + c9a6811 commit 813372b2b61995ebcc129f7ae055364249d71fcb @tmm1 tmm1 committed Dec 10, 2011
Showing with 4 additions and 1 deletion.
  1. +1 −1 lib/bert/encode.rb
  2. +3 −0 test/encoder_test.rb
View
@@ -78,7 +78,7 @@ def write_float(float)
end
def write_bignum(num)
- n = (num.to_s(2).size / 8.0).ceil
+ n = (num.abs.to_s(2).size / 8.0).ceil
if n < 256
write_1 SMALL_BIGNUM
write_1 n
View
@@ -82,6 +82,9 @@ class EncoderTest < Test::Unit::TestCase
should "handle bignums" do
bert = [131,110,8,0,0,0,232,137,4,35,199,138].pack('c*')
assert_equal bert, BERT::Encoder.encode(10_000_000_000_000_000_000)
+
+ bert = [131,110,8,1,0,0,232,137,4,35,199,138].pack('c*')
+ assert_equal bert, BERT::Encoder.encode(-10_000_000_000_000_000_000)
end
should "leave other stuff alone" do

0 comments on commit 813372b

Please sign in to comment.