Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!ucsfcgl!conrad From: conrad@cgl.ucsf.edu (Conrad Huang) Newsgroups: comp.sys.sgi Subject: Re: IRIX 3.2 C compiler bug Message-ID: <12999@cgl.ucsf.EDU> Date: 5 Feb 90 18:40:44 GMT References: <90Feb5.000622est.4918@neat.cs.toronto.edu> <13583@phoenix.Princeton.EDU> Sender: daemon@cgl.ucsf.edu Lines: 39 >>On a 4D/240S running 3.2: >> % cat t.c >> main() >> { >> double a,b,c; >> >> b = 1.0; >> c = 2.0; >> a = b==c; >> printf("a=%f\n",a); >> } >> % cc t.c >> % ./a.out >> a=2147469288.000000 >Just what did you expect this to return? Unless I am mistaken, ANSI C >still doesn't any distinction about what number is returned, only that >it is NOT zero, which is certainly the case for your code here. It is probably >also true that comparison of floating point numbers is an inherently dicey >proposition. Say what!? In K&R, Appendix A, page 189, Section 7.6, "The operators < (less than), > (greater than), <= (less than or equal to) and >= (greater than or equal to) all yield 0 if the spricified relation is false, and 1 if it is true" and on page 190, Section 7.7, "The == (equal to) and the != (not equal to) operators are exactly analogous to the relation operators except for their lower precedence." Please tell me if ANSI C has revoked these statements! So... In the first place, the program ought to print 0, since 1.0 == 2.0 is *false*. In the second place, even if they were equal, it should print 1.000000. Conrad