Re: [encoding] Fix #20: rather than relying on integer division, use floor() (929a3ff)

Consider `(X/Y)/Z`.  Given nonnegative integers X, Y, Z, the exact result of `X/Y` will be `N + f`, where `N` is an integer and `0 <= f <= (Y-1/Y)` (since X is an integer).  Then `(X/Y)/Z = (N + f)/Z = N/Z + f/Z = (N' + f') + f/Z` where `N'` is an integer and `0 <= f' <= (Z-1/Z)`.  We cwant to ensure that `(f' + f/Z) < 1`. Expanding, `f' + f/Z <= (Z-1/Z) + (Y-1/YZ)` and so `f' + f/Z <= (YZ-1/YZ)`.  That will always be less than 1 *assuming X Y Z are nonnegative integers* (which they seem to be in this case).

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/encoding/commit/929a3ffec7695b38c1b5529411de52eca6935d61#commitcomment-15021593

Received on Wednesday, 16 December 2015 18:03:26 UTC