Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!agate!eris.berkeley.edu!bowles From: bowles@eris.berkeley.edu (Jeff A. Bowles) Newsgroups: comp.lang.c Subject: Re: doubles used as booleans Keywords: double,float,boolean Message-ID: <22352@agate.BERKELEY.EDU> Date: 30 Mar 89 21:00:08 GMT References: <8269@xanth.cs.odu.edu> Sender: usenet@agate.BERKELEY.EDU Distribution: na Organization: University of California, Berkeley Lines: 19 In article <8269@xanth.cs.odu.edu> kremer@cs.odu.edu (Lloyd Kremer) writes: > > Can a double be used directly as a boolean? I don't have a copy of ANSI, but you don't need it for part of the answer: "Are you really, absolutely sure you wanna compare a floating-point number to ANYTHING else, just to see if the numbers are EQUAL?" If you're interested in if a floating-point variable is equal to another floating-point variable, or if it's equal to zero, well, umm, think very carefully about whether you're getting ready to shoot yourself in the foot. It's the same type of thing that makes 3*(1.0/3.0) not equal to 1.0.... Jeff Bowles ps. Comparing to some small amount, like "abs(x) < 0.00001", doesn't do a lot better when the calculations are smaller than that, either.