Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!ncar!midway!arthur!francis From: francis@arthur.uchicago.edu (Francis Stracke) Newsgroups: comp.sys.mac.programmer Subject: Re: Why can't the Mac add? Message-ID: <1990Sep26.221434.16812@midway.uchicago.edu> Date: 26 Sep 90 22:14:34 GMT References: <45060@apple.Apple.COM> <4485@sage.cc.purdue.edu> Sender: news@midway.uchicago.edu (News Administrator) Organization: Mathematics Department, University of Chicago Lines: 24 In article <4485@sage.cc.purdue.edu> ar4@sage.cc.purdue.edu (Piper Keairnes) writes: >In <45060@apple.Apple.COM> das@Apple.COM (David Shayer) writes: > >>I was running this simple program. > >>main () >>{ >> float x; >> >> for (x=0.0;x!=10.0;x+=0.2) >> printf ("x=%f \n",x); >>} > >That isn't that simple of a program when dealing with floating point >numbers. There is no such thing as an EXACT floating point number. Floating >point numbers are close approximations to real numbers. The problem is that, in binary, 0.2 is 0.001100110011... (repeating 0011 forever, in case you can't guess--in base 10 we'd call it a repeating decimal.) Think of what happens if you try to add 1/3 in base 10 with small precision: 0.3333, 0.6666, 0.9999, 1.3332, 1.6665, 1.9998 And so on. If you ever want to do fractions on a computer, do them as fractions, not as reals. (SANE has the Fixed type, doesn't it?)