logoalt Hacker News

danielEMyesterday at 7:39 AM1 replyview on HN

Sorry, just did that test - it is 1075, not massive, I would risk saying that may be major issue of this lib.

Here is the code:

let left = 0, right = 1

let rightPrevious = 2

let counter = 0;

while (right > left && right < rightPrevious) {

    rightPrevious = right;

    right /= 2;

    counter++
}

console.log(counter)

Did look very briefly into repo, but didn't find a place where it is handled and don't have time to dig it, but if that issue is true I may help with resolving it. LMK


Replies

paulgbyesterday at 7:56 AM

Good point. Usually fractional indexing is done with arbitrary-precision numbers to avoid exactly this issue. We landed on using JS floats to teach the technique because it makes it more intuitive to understand what’s going on, but you make a good point and I’ll make sure we add that caveat and link out to an arbitrary-precision fractional index library.