2D SmallHilbertCurve with 16 bits gives negative numbers for arguments with x > 2^15
FunMiles opened this issue · 5 comments
Up to nbits=15 all is fine. But for nbits=16 the whole right half plane gives negative coordinates.
I am using the code from maven, but I suspect, looking at the source that this line (72) is to blame:
b |= 1 << bIndex;
It should be
b |= 1L << bIndex;
Excuse the delay!
This rings a bell inasmuch as I think I've been down that path before (and making that change breaks other stuff), how many dimensions are you using? I might need to revisit the threshold check on forcing the user to use the BigInteger index.
I've just had a look and your suggested fix looks sensible. All tests pass with that change so I'll need to come up with a failing test to confirm. I'll let you know how I go.
Good find @FunMiles, thank you very much. I've added a round trip test for the scenario below and it passes with your fix :
bits = 16
dimensions = 2
index = 2^ (bits*dimensions-1) + 1
I'll release the fix now.
I've released 0.1.3 to Maven Central. Usually visible there within 10 mins or so.
@FunMiles please try your use case again with 0.1.3 to see if all well, thanks.