Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!ncar!noao!arizona!dave From: dave@cs.arizona.edu (Dave Schaumann) Newsgroups: comp.lang.c Subject: Re: Simple atof() question Message-ID: <1237@caslon.cs.arizona.edu> Date: 21 Mar 91 05:52:34 GMT References: <1214@caslon.cs.arizona.edu> <15522@smoke.brl.mil> Organization: U of Arizona CS Dept, Tucson Lines: 17 In article <15522@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >In article <1214@caslon.cs.arizona.edu> armstron@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@cs.arizona.edu | Short .sig's rule!