Simple atof() question

Dave Schaumann dave at cs.arizona.edu
Thu Mar 21 15:52:34 AEST 1991


In article <15522 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <1214 at caslon.cs.arizona.edu> armstron at cs.arizona.edu (Jim Armstrong) writes:
>>When I run this simple program I get n = 37.549999 instead of
>>n = 37.55.  What am I doing wrong?
>
>[...]
>I think your real problem is that you think that the value 37.55 can
>be represented exactly in a binary floating-point representation.

Reminds me of a quote I heard or read somewhere.  (sorry, can't remember,
but feel free to enlighten me if you know...)

	Using floating point arithmetic is like moving piles of sand.
	Every time you do, you lose a little sand and pick up a little dirt.

-- 
Dave Schaumann | dave at cs.arizona.edu | Short .sig's rule!



More information about the Comp.lang.c mailing list