Skip to content

Commit b6e5de3

Browse files
committed
fix: adjust twos complement return value for zero in bigIntToTwosComplement
1 parent a7f4c07 commit b6e5de3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

buffer_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,11 @@ func TestDecimalColumnShopspring(t *testing.T) {
618618
value: fakeShopspringDecimal{coeff: big.NewInt(12345), exp: -2},
619619
expectedBytes: []byte{0x17, 0x02, 0x02, 0x30, 0x39},
620620
},
621+
{
622+
name: "zero",
623+
value: fakeShopspringDecimal{coeff: big.NewInt(0), exp: 0},
624+
expectedBytes: []byte{0x17, 0x00, 0x01, 0x00},
625+
},
621626
{
622627
name: "positive exponent multiplies coefficient",
623628
value: fakeShopspringDecimal{coeff: big.NewInt(123), exp: 2},

decimal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func bigPow10(exponent int) *big.Int {
165165

166166
func bigIntToTwosComplement(value *big.Int) ([32]byte, uint8, error) {
167167
if value.Sign() == 0 {
168-
return [32]byte{0}, 32, nil
168+
return [32]byte{0}, 31, nil
169169
}
170170
if value.Sign() > 0 {
171171
bytes := value.Bytes()

0 commit comments

Comments
 (0)