[Tutor] Why doesn't this work??

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Mon, 31 Jul 2000 16:40:23 -0700 (PDT)

On Mon, 31 Jul 2000, Deirdre Saoirse wrote:

> On Mon, 31 Jul 2000, Carl Kreider wrote:
> > I agree that 0, 20, 30, and 40 mod 10 yield 0, but since
> > when does 10, 50, or 60 mod 10 yield 10?  Do I misremember
> > how mod works?
> mod is an integer-based function, so yes, you misremembered.

Mod actually does work on floating point numbers.  The problem that
you're encountering has to do with limited precision.  That is, the larger
the number becomes, the less precise the number becomes.

Let's take a look again at that weird case:

  ttp: T=6.000000 num=60.000000 den=10.000000 ttp=10.000000

In this particularly perverse case, a number like 60.000000000 is probably
represented as 59.9999999999999999... or something like that.  I'll be
very wishy washy at this point --- this means that grabbing the remainder
of 60.0 / 10.0 will get you 9.999999999999... as a remainder.  
Afterwards, when you print it again, you'll get 10.0.  Very very evil...

Your program is particuarily cool in that it shows this bug clearly ---
you might want to keep it!