doubles used as booleans

Jeff A. Bowles bowles at eris.berkeley.edu
Fri Mar 31 07:00:08 AEST 1989


In article <8269 at xanth.cs.odu.edu> kremer at 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.



More information about the Comp.lang.c mailing list