Permalink
Browse files

fixed encoding of negative bignums

  • Loading branch information...
1 parent 5d55823 commit c9a6811cc39b6fe9a3a8cf460b89eccecc9b5135 @dgrijalva dgrijalva committed Aug 25, 2010
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 c9a6811

Please sign in to comment.