From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,4f7a405235f760ec X-Google-Attributes: gid1164f8,public From: phil@pottsoft.demon.co.uk (Phil Ottewell) Subject: Re: Bug in C compiler? Date: 1996/09/20 Message-ID: <1996Sep20.010952.157@pottsoft.demon.co.uk>#1/1 X-Deja-AN: 184063436 x-nntp-posting-host: pottsoft.demon.co.uk references: <4buf2zhlw.fsf@ruls41.fsw.LeidenUniv.nl> organization: POttSoft newsgroups: comp.sys.dec -----BEGIN PGP SIGNED MESSAGE----- In article <4buf2zhlw.fsf@ruls41.fsw.LeidenUniv.nl>, vosse@ruls41.fsw.LeidenUniv.nl (Theo Vosse) writes: [snip] > double factor = 1.0 / pow(2.0, b); > > which fills a table with binomial probabilities. The problem is that > when I use DEC's c compiler (with -g), 'factor' becomes 0.707106..., > which is sqrt(2), whereas when I use gcc, it becomes 1/(2**b). The > last one is correct. I saw a bug very similar to this on DEC C for VMS. It was actually my fault, because I had omitted to include math.h, and as I recall the code was (correctly because I hadn't declared it) interpreting the floating point 'bit pattern', returned by the function, as an _integer_ . It was then doing a calculation similar to yours, so it converted the 'integer' to double and gave the unexpected result. Once I had tracked down the cause, I wondered why I hadn't received and 'implicit function type' whinge from the compiler. It took me several hours to track the problem down to a buglet in the types.h standard header. Near the top was a "#pragma __nostandard" but there was no corresponding "#pragma __standard" at the bottom to turn the warnings back on. So, anything that included types.h (and this tended to be indirectly, via X11 headers for example) had the warnings switched off ! This was fixed by DEC C 5.3 I believe. Short version: Have you included math.h ? :-) -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: noconv iQCVAwUBMkHu0gFrKHWv1IPxAQEKSAQAxR7HpHhIaYzcp9rOed4n7KbWJfTcZJQD /rggaWqcOCH7Bxg2SCr6fHcP8ErsblNQuAxf+8na7LxqGqPaZFuMBe3MRdt03vee AkTz3VTq7OK897WGqDsG6xd7G3nT234NgXHG3IlZ+Qg/XTyCs39mRwJsM5IXSQXT HevJrf6w8Dc= =wB+0 -----END PGP SIGNATURE----- -- Phil Ottewell - PGP Key ID: 0xAFD483F1 - WWW: http://www.pottsoft.demon.co.uk/