
On 10/26/2010 12:27 PM, Scott McMurray wrote:
On Tue, Oct 26, 2010 at 10:01, John Maddock
wrote: Of course this assumes that parameter "f" is exactly representable as a floating point value, in fact it might need to be a power of 2 in order to be certain of being completely safe and accurate....
"Safe and accurate" is always far beyond my ability to prove when it comes to floating point.
Yeah mine too. Still, I always though multiplication and division by powers of two was one thing it was expected to do well. Seems like it could usually just change the exponent and not lose any precision in the mantissa.
Even if f is a power of two, what is something like round2fraction(sqrt(1e41), 4) supposed to do?
The magnitude of 1e41, sqrt(1e41), and sqrt(1e41)*4 all fit neatly into double precision, so couldn't round2fraction give an exact answer in this case?
Perhaps the best it can promise is something like "when the result is displayed with digits10-1 significant figures, it will appear to have been rounded as requested".
It doesn't sound to me like it's any worse than your typical floating point multiplication (well, maybe two of them). Perhaps you could define the precision of its result as being "no worse, on average, than the expression f*round(x/f)". :-) - Marsh