http://bugs.winehq.org/show_bug.cgi?id=18916
--- Comment #19 from Michael Abbott michael@araneidae.co.uk 2009-06-17 03:21:33 --- This is all completely irrelevant now, but I was puzzling over how to get that last bit of rounding right in this calculation:
WORD d15 = source[x] & 0xfffe; DWORD d24 = (d15 << 8) + (d15 >> 7);
This produces a worst error of +-0.9825; if we allow for the fact that we have to round (so can subtract 0.5 from this error), we have an error of +-0.4825.
Here's the best I can do (really not suggesting this goes into the code, this is just one of those details that bugs me until I can write it out):
DWORD d15 = (source[x] & 0xfffe) << 7; DWORD d32 = (d15 << 9) + (d15 >> 6) - (d15 >> 15) + (1 << 7) DWORD d24 = d32 >> 8;
This isn't perfect, but we *nearly* get the bottom bit right -- in fact, this only get it wrong 166 times out of 32768. The worst error is -0.5106..+0.5029, or after compensating for rounding, -0.0106..+0.0029.
Ah well -- your original calculation gets this perfect (error +-0.4999, or 0 after rounding). These elusive last bits in simplified division are annoying, I have this annoyance elsewhere (again, in a context where the proper response is "who cares?").