In article , Jerry Avins writes: |> |> > !!! Well, I suggest that the people who claim that contact someone |> > who knows how to do it. As I said, I have done it in both integers |> > and floating-point. It isn't hard, and doesn't need extended precision. |> > It does need skill and care - whether it is done in integers or |> > floating-point. |> |> It's not so simple when the exponent might change, but it's very |> straight-forward with integer or fixed point. Many microprocessors |> natively implement floored division with remainder, so most of what |> needs doing is taken care of by the hardware.
No, it's actually equally simple in any faithful (a technical term) floating-point.
The key is that (for positive numbers) X-wombat(X) is exact, where wombat() is a function that maintains the exponent of X, returns the next power of the base above X or is a normalised form of something that would be exact when unnormalised with the exponent of X. The functions floor, ceil, nearest and others all meet the requirements.
This means that you can subtract where you are from where you want to be and not lose accuracy. In general, the implicit double precision provides enough extra accuracy to ensure that you always close the loop - because, if it didn't, you have other problems. It also means that you can implement double precision addition by a few statements, which is where the technique originated.
Regards, Nick Maclaren.