[Courses] [C] Difficult bug (Re: Debugging)

Mary mary-linuxchix at puzzling.org
Wed Jul 10 12:09:25 EST 2002


On Wed, Jul 10, 2002 at 12:03:15PM +1000, Mary wrote:
> But why is 1.01 * 100 equal to 100.999999? You've uncovered a quite
> subtle set of errors that occur with floating point numbers.
> 
> Your next step is reading about floating point errors:
> 
> A general tute:
> http://www.ug.cs.usyd.edu.au/~cs2/soft2004/s1_2002/tutes/week10/
> 
> And an answer to this specific bug:
> http://www.eskimo.com/~scs/C-faq/q14.1.html

I thought I should also note that this is a subtle bug, and it took me
about an hour to properly figure out the solution (and that's from
someone who knows about floating point errors and has tutored C). I
actually thought the bug was somewhere else for quite a while and went
charging ahead before I checked that the multiplication was happening
correctly. The print bugfinding solution isn't something for beginners
alone -  I didn;'t just do it to show you how, I did it because I needed
to find the bug myself. And I was wrong about where it was, so it's a
good thing I was being so careful.

-Mary.



More information about the Courses mailing list