On Thu, 2 Aug 2007, Joshua Isom wrote: > I'm pretty sure 0.0 always equals -0.0. I think it's part of the c > specification. Now, on OpenBSD, you can't print -0.0, as it will print 0.0 > instead which is really annoying. This is with at least 3.8 but I don't know > if it's been changed since then. Anyway, to test for -0.0 instead of 0.0, you > have to use copysign.
I'm afraid copysign() is not generally suitable (though it may be on some platforms). On Linux, the copysign(3) man page has the following caveat: The copysign() functions may treat a negative zero as positive. Alas, there's no further information, so it's not obvious when such misbehavior might occur. In a C99 system, you should use signbit(3) instead, though you may need extra compiler flags or libraries to find it. In the absence of signbit(3), there are various bitwise tricks one can often use. Some of these are scattered about in config/gen/platform/*/math.h. > Anyway, comparing equality of floats is never accurate, since the floats > themselves are inaccurate. I disagree. In some circumstances, comparing to 0.0 can be perfectly well defined. This whole discussion seems pointless. The accuracy of floating point calculations depends sensitively on what, precisely, the programmer is attempting to do. Guessing programmer intent doesn't seem to me to be an appropriate job for a virtual machine. -- Andy Dougherty [EMAIL PROTECTED]