Subject: Bfloat conversion of rationals can be inaccurate
From: Raymond Toy
Date: Fri, 11 Dec 2009 18:27:25 -0500
Maxima currently converts rationals by bfloating the numerator and
denominator and then performing a bfloat division. This is probably ok,
but consider what happens if the numerator and/or denominator has more
than fpprec digits. We then get two rounding operations, and then one
more for the division.
We can do better than that. We should left shift the numerator by
enough bits so that the numerator divided by the denominator produces
fpprec digits. The remainder tells us how to round the result. This
gives us the nearest bfloat to the rational, with just the one rounding
needed.
I noticed that some of the differences between the current and fast
bfloat input routines appear to be actually incorrect values for the
current algorithm. I think this is caused by the inaccurate conversion
of rationals.
Ray