bloom icon indicating copy to clipboard operation
bloom copied to clipboard

Approximated Size returns 0 for a saturated bitset on amd64

Open rotemiman opened this issue 1 year ago • 0 comments
trafficstars

It seems that Go's behavior when casting Positive Infinity to uint32 is architecture specific. This causes theApproximatedSize calculation to return an inconsistent value between architectures.

If you run this:

saturatedBloom := bloom.FromWithM(bitset.New(10000).Complement().Bytes(), 10000, 4)
fmt.Println(saturatedBloom.ApproximatedSize())

In amd64, it prints 0, while if you run it on arm64, it prints the max value for uint32.

For a smaller example:

fmt.Println(uint32(math.Inf(1)))

Is equivalent.

I'd expect a saturated bloom to return a very high number and not zero, so I'd propose checking first for a saturated bloom and returning max uint32 explicitly.

See: https://github.com/golang/go/issues/56023

rotemiman avatar Aug 21 '24 07:08 rotemiman