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

get RangeError when adding interval with 1073741824 / 1073741825 #8

Open
brycehanscomb opened this issue Nov 18, 2014 · 2 comments
Open

Comments

@brycehanscomb
Copy link

The following line produces a RangeError:

new IntervalTree(1).add([1073741824, 1073741825, 'hello']);

The exact error in Chrome is:

Uncaught RangeError: Maximum call stack size exceeded - SortedList.js:26
@fredericgermain
Copy link

I got this when I initialize IntervalTree with a bad value (actually, the max value I intented to have in the tree).
When initializing with the medium value (max-min)/2, it was ok

@occidens
Copy link
Contributor

When the midpoint of intervals was calculated by bit shifting (prior to f7166f0), the error that @brycehanscomb encountered was due to the fact, when bit shifting, Java considers integers to be in a 32-bit signed representation. 1,073,741,824 + 1,073,741,825 = 2,147,483,648, which is greater than the largest 32-bit signed integer, 2,147,483,647. Thus 1073741824 + 1073741825 >> 1 gives the wrong answer because it wraps around to a negative number.

@fredericgermain, by the time you looked at this, you were seeing a different problem that was due to a typo in the new code for finding the interval midpoints. PR #11 should resolve this. And using / 2 instead of >> 1 to divide by 2 means that the full allowable range of integers can be used.

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

3 participants