On 8/31/07, Morton Goldberg <m_goldberg / ameritech.net> wrote:
> That's true ...
>
> > ... and it doesn't fit 10 whole times in 1.0. This has nothing to do
> > with the algorithm used.
>
> ... but Ruby appears to think otherwise
>
>     sprintf("%.25f", 1.0/0.1) # => "10.0000000000000000000000000"
>
> causing me to conclude something is amiss in the % operator algorithm.

From what I can gather from the source code for the numeric, it is
using C's fmod (from math.h) to do the actual calculation and THAT
function is "broken" (see
http://www.ruby-doc.org/doxygen/1.8.4/numeric_8c-source.html for the
source code. Relevant portions are at lines 646 through 705).

However (as I've noted before), modf DOES work and if we were to set
the define for HAVE_FMOD to 0 instead of 1 at compile time, that code
would be used and (from what I can tell) % would work properly.

The more I look at this problem, the more confused I get though.
Sadly, this is my first real experience with floats where I've noticed
that they are not so precise. So I'm still trying to catch up a bit.

Charlie