Skip to content
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

IsNegtive exist bug #462

Open
ChicChip opened this issue Nov 27, 2024 · 4 comments
Open

IsNegtive exist bug #462

ChicChip opened this issue Nov 27, 2024 · 4 comments

Comments

@ChicChip
Copy link

ChicChip commented Nov 27, 2024

When using roaring64.BSI, due to value type is *big.Int , bsi's bitCount is Variable length even if some negative value is set. Thus there is a bug, when bsi's min negative value's bitLen is less than max positive num, GetValue will get wrong error.

testcode
bsi := roaring64.NewDefaultBSI()
for i:=-100;i<100;i++ {
bsi.SetValue(uint64(i+100),int64(i))
}
fmt.Println(bsi.GetValue(0))
result is -100, true

bsi := roaring64.NewDefaultBSI()
for i:=-100;i<1000;i++ {
bsi.SetValue(uint64(i+100),int64(i))
}
fmt.Println(bsi.GetValue(0))
result is 156, true

So if code uses len(b.bA) as sign bit may not work

@ChicChip ChicChip changed the title IsNegtive exist big bug IsNegtive exist bug Nov 27, 2024
@guymolinari
Copy link
Contributor

guymolinari commented Nov 27, 2024 via email

@ChicChip
Copy link
Author

  1. unit test will pass

func TestGetNegativeValue(t *testing.T) {
num := int64(14)
bsi := NewDefaultBSI()
for i:=-num; i<=num;i++ {
bsi.SetValue(uint64(i+num), i)
}
val, _ := bsi.GetValue(0)
assert.Equal(t, -num, val)
bsi.SetValue(uint64((num+1)+num), num+1)
val, _ = bsi.GetValue(0)
assert.Equal(t, -num, val)
}

  1. unit test will fail, when set value 16 to bsi, bsi's higthest bit is not sign bit
    func TestGetNegativeValue(t *testing.T) {
    num := int64(15)
    bsi := NewDefaultBSI()
    for i:=-num; i<=num;i++ {
    bsi.SetValue(uint64(i+num), i)
    }
    val, _ := bsi.GetValue(0)
    assert.Equal(t, -num, val)
    bsi.SetValue(uint64((num+1)+num), num+1)
    val, _ = bsi.GetValue(0)
    assert.Equal(t, -num, val)
    }
    Error: Not equal:
    expected: -15
    actual : 17
    Test: TestGetNegativeValue
    --- FAIL: TestGetNegativeValue (0.00s)

@guymolinari
Copy link
Contributor

guymolinari commented Nov 27, 2024 via email

@ChicChip
Copy link
Author

Are you attempting to set columnId to a negative value?

On Wed, Nov 27, 2024 at 8:02 AM ChicChip @.**> wrote: 1. unit test will pass func TestGetNegativeValue(t testing.T) { num := int64(14) bsi := NewDefaultBSI() for i:=-num; i<=num;i++ { bsi.SetValue(uint64(i+num), i) } val, _ := bsi.GetValue(0) assert.Equal(t, -num, val) bsi.SetValue(uint64((num+1)+num), num+1) val, _ = bsi.GetValue(0) assert.Equal(t, -num, val) } 2. unit test will fail, when set value 16 to bsi, bsi's higthest bit is not sign bit func TestGetNegativeValue(t testing.T) { num := int64(15) bsi := NewDefaultBSI() for i:=-num; i<=num;i++ { bsi.SetValue(uint64(i+num), i) } val, _ := bsi.GetValue(0) assert.Equal(t, -num, val) bsi.SetValue(uint64((num+1)+num), num+1) val, _ = bsi.GetValue(0) assert.Equal(t, -num, val) } Error: Not equal: expected: -15 actual : 17 Test: TestGetNegativeValue --- FAIL: TestGetNegativeValue (0.00s) — Reply to this email directly, view it on GitHub <#462 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZZAUTPTVSHT53FOZJRTDD2CXGHNAVCNFSM6AAAAABSSM5VLKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBTHE2TQMRWGM . You are receiving this because you commented.Message ID: @.>

no, in this code, you can see columnId is >=0, only value may a negtive number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants