After some testing, this extra 1 pixel definitely rounds out the error. All three of these variables (document height, window height, and scroll top) are supported either with some greater internal precision or with the scale of the boundless browser window, and then scaled and rounded as necessary according to the requirements of JavaScript properties. In some cases, crosses that become more likely as the scaling factor increases, these values ββare rounded so that you see inconsistent results that you saw.
If you do not adjust one of these variables many times faster, based on the values ββof the other variables, this rounding error is unlikely to cause problems for the user. If you need to configure them often, you should probably cache the adjusted numbers and use your cached versions instead of the numbers displayed in the browser for further calculations.
[Note. In the end, I managed to get a -1 rounding error using the formula in OP, with a 250% increase in Firefox.]
source share