On Mon, 20 Aug 2007, Nicholas Clark wrote: > On Mon, Aug 20, 2007 at 10:18:33AM -0400, Andy Dougherty wrote:
> > Your trick (extended, if needed, by clever Configure.pl probes) will > > cleverly suppress the warning for the f == 0 case, while still retaining > > the exact comparison. (Hmm. Not sure about negative zero offhand. I'd > > have to test.) > > I'm not convinced that it's great. It assumes > > 1: that the floating point representation is all bits zero [Alphas can run in > non IEEE, IIRC] > 2: that there is an integer type exactly the same size as the floating point > type. (Larger and smaller will both have problems) Yes. This sort of thing is what I meant by "clever Configure.pl probes". Configure.pl could figure out what the bit pattern is for a FLOATVAL of 0.0. And check for -0.0, and then do special testing for the 10-byte variety, and perhaps even more special testing for the extra precision that math co-processors used to keep (but throw away when it moved values into registers) (Insert painful flashback of post-processing 68000 assembler output to use a math coprocessor). But it's doable, I think, with persistence and a reasonable amount of useful feedback. > I can't think of a clean, portable, efficient way to test that a floating > point variable is zero other than == 0.0; Nor can I. Thus you either use lots of platform-specific code (determined by Configure.pl) or turn off gcc's -Wfloat-equal warning flag and just write f == 0.0. Personally, I'd just turn off the -Wfloat-equal flag, but I have no objection if someone else wants to do all the work to do it the other way. -- Andy Dougherty [EMAIL PROTECTED]