Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!think.com!sdd.hp.com!ucsd!ucbvax!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!warwick!asrap From: asrap@warwick.ac.uk (Sean Legassick) Newsgroups: comp.lang.c Subject: Re: Nasty bug Message-ID: <1990Aug31.115751.8649@warwick.ac.uk> Date: 31 Aug 90 11:57:51 GMT References: <0093BF08.7F3834E0@rigel.efd.lth.se> <11473@crdgw1.crd.ge.com> Sender: news@warwick.ac.uk (Network news) Organization: University of Warwick, UK Lines: 38 In article <11473@crdgw1.crd.ge.com> volpe@underdog.crd.ge.com (Christopher R Volpe) writes: =In article <0093BF08.7F3834E0@rigel.efd.lth.se>, e89hse@rigel.efd.lth.se =writes: =|>Later I rewrote =|>prnval() as: =|> =|>prnval(s,f) =|>char *s; =|>double f; =|>{ =|> if(f == 0.0) =|> sscanf(s,"%lf",&f); =|> printf("%10.2f\n",f); =|>} = =This is the correct solution anyway. There is still a possible problem though. Comparing floating-point values to 0 like that can cause problems, especially if the values been put through the mangle of promotion etc. Its far less likely to cause problems if you use something like : if (f < 0.005) As the orginal poster did not describe the nature of the problem when the program was run (or compiled) this could have been the cause. =|> =|> Henrik Sandell = =================== =Chris Volpe =G.E. Corporate R&D =volpecr@crd.ge.com --------------------------------------------------------------------------- Sean Legassick, cuuee@uk.ac.warwick.cu "Improbability factor of one Computing Services asrap@uk.ac.warwick.cu to one. We have normality. University of Warwick Anything you still can't (the walking C obfuscator!) handle is your own problem."