Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: phil@pottsoft.demon.co.uk (Phil Ottewell)
Subject: Re: Bug in C compiler?
Date: 1996/09/20	[thread overview]
Message-ID: <1996Sep20.010952.157@pottsoft.demon.co.uk> (raw)
In-Reply-To: 4buf2zhlw.fsf@ruls41.fsw.LeidenUniv.nl


-----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/



      parent reply	other threads:[~1996-09-20  4:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-19  4:00 Bug in C compiler? Theo Vosse
1996-09-19  4:00 ` Stephen Hoff Hoffman
1996-09-19  4:00 ` Ron Natalie
1996-09-19  4:00   ` Ron Natalie
1996-09-20  4:00 ` Theo Vosse
1996-09-20  4:00 ` Phil Ottewell [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox