Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!das From: das@Apple.COM (David Shayer) Newsgroups: comp.sys.mac.programmer Subject: Re: Why can't the Mac add? Message-ID: <45072@apple.Apple.COM> Date: 24 Sep 90 01:17:19 GMT References: <45060@apple.Apple.COM> <1990Sep23.061645.17161@d.cs.okstate.edu> Organization: Apple Computer Inc., Cupertino, CA Lines: 30 I guess I should have been clearer in my last posting, and I wouldn't have gotten flamed in my email. I was asking about this code: >> main () >> { >> float x; >> >> for (x=0.0;x!=10.0;x+=0.2) >> printf ("x=%f \n",x); >> } I am not using this code in any program. I would not use a != test in a real program, I would use a <. I understand that 0.2 does not convert perfectly to binary, and thus precision is lost. I had thought that the reason people wrote complex floating point software like SANE was to fix situations like this by have bits indicating that a numerical pattern repeated indefinitely. Suppose you calculated two real numbers, and you wanted to see if the results were the same. It seems that you could never use a simple equality (==) test, as that would often fail even when the numbers were the same when calculated with infinite precision. I take it from people's responses that this problem has not been solved, even with SANE. Is there a better way than simply seeing if the numbers are sufficiently close? David