Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!apple!das From: das@Apple.COM (David Shayer) Newsgroups: comp.sys.mac.programmer Subject: Why can't the Mac add? Message-ID: <45060@apple.Apple.COM> Date: 23 Sep 90 00:02:26 GMT Organization: Apple Computer Inc., Cupertino, CA Lines: 29 I was running this simple program. main () { float x; for (x=0.0;x!=10.0;x+=0.2) printf ("x=%f \n",x); } As you can see, it ought to stop when x==10.0. However, it actually runs in an infinite loop. This is because x never equals exactly 10.0. The +0.2 always makes x equal to 9.999999 or 10.000001 or something. Changing x from a float to a double makes x stay closer to the correct value, but it still isn't exactly correct, and as the loop runs longer, x gets off more and more. So my question is, why can't the Mac do simple math? What's going on here? Is SANE insane? I have a Mac IIci, so I have a 68882 FPU. This program fails in both Think and MPW C. I didn't compile with any special FPU options on. A friend ran it on a PC clone, and it failed in the same way there. Please enlighten me. David