Article View: comp.sys.mac
Article #23731Serious MPW C bug!
From: Mike Blackwell
Date: Tue, 19 Jan 1988 04:24
Date: Tue, 19 Jan 1988 04:24
35 lines
1761 bytes
1761 bytes
If you're using MPW 2.0 C, beware of floating point operations. I just spent
two hours tracking down the following bug (it took that long, because it was
a complicated program, and I didn't even think to look for such a major
compiler bug). Try this simple program:
#include <stdio.h>
main()
{
float a, b, c;
a = 2.0; b = 3.0; c = 0.0;
c += a * b;
printf("a = %f, b = %f, a*b = %f, c = %f\n", a, b, a * b, c);
}
Guess what you get...
a = 2.0000, b = 3.0000, a*b = 6.0000, c = 0.0000
In fact, trying to get around this with c = c + a * b; will also give you
the same results! The same holds true for using doubles or comps instead of
floats. Using extendeds does seem to work, however. I still can't believe
this. And this DID work in the beta release of 2.0! Arrrrrggggghhhhhh!!!!!!
While I'm bitching about MPW, quick and dirty programs which just use stdio
for output (like this one) crash instantly under Multifinder. And you'd
think, with the horsepower of a Mac2 on my desk, I could compile, or at
least print, in the background, but nooo.... Most every other application
can take advantage of background printing these days. Humph. And I used to
love MPW.
Mike Blackwell
The Robotics Institute, Carnegie-Mellon University
ARPA: mkb@rover.ri.cmu.edu
(412) 268-8830
Technical Details
Message-ID:
<674@PT.CS.CMU.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!ROVER.RI.CMU.EDU!mkbShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!ROVER.RI.CMU.EDU!mkb From: mkb@ROVER.RI.CMU.EDU (Mike Blackwell) Newsgroups: comp.sys.mac Subject: Serious MPW C bug! Message-ID: <674@PT.CS.CMU.EDU> Date: 19 Jan 88 04:24:06 GMT Sender: netnews@PT.CS.CMU.EDU Reply-To: mkb@rover.ri.cmu.edu (Mike Blackwell) Organization: Carnegie-Mellon University, CS/RI Lines: 35