englercj / resource-loader

A middleware-style generic resource loader built with web games in mind.
http://englercj.github.io/resource-loader/
MIT License
424 stars 77 forks source link

progress cumulative precision error #110

Closed ladrower closed 6 years ago

ladrower commented 6 years ago

This is related to cumulative precision error that in some cases might exceed 100. It depends on number of chunks that own distributed progress parts.

Trivial example in JS:

// for console
c = i = 6, t = 0; while (i-- > 0) t += 100/c; t
100.00000000000001

// OR more readable

const total = 29;
let progress = 0;
let i = total;
while (i > 0) {
    progress += 100/total;
    i--;
}
console.log(progress === 100.00000000000004); // true
englercj commented 6 years ago

Hey @ladrower, thanks for putting this together.

If you could fix up the linting errors I'd be happy to merge this in.

ladrower commented 6 years ago

Hey @englercj, no problem. Seems OK now. Sorry for this.

englercj commented 6 years ago

Thanks again for this @ladrower I'll get a release out soon.