IRIX 3.2 C compiler bug
Conrad Huang
conrad at cgl.ucsf.edu
Tue Feb 6 05:40:44 AEST 1990
>>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
More information about the Comp.sys.sgi
mailing list