
"Robert Ramey" <ramey@rrsd.com> writes:
Peter Dimov wrote:
It depends. Where do you draw the line? Is inf a number? Is -0.0 a number? You have to have NaN if you want to be able to represent x/y as a float.
That's the problem. x/y is not a valid operation if y is equal to 0. So it can't be represented as a number.
The fact that C++ permits such an operation makes C++ different than arithmetic. The fact that C++ uses operators like "/" and defines them similar to - but not identical to - the way they are defined by standard arithmetic is the source of all these problems.
Well, you'd better come up with a new number representation, then. assert(2/3*3 == 2); // boom assert(2.0/3.0*3.0 == 2.0); // boom
I say that C++ should be changed to so that the floats and operators which apply to them should implement what people expect from arithmetic operators.
That would be great, wouldn't it, LOL? (there, I get to use that one this time) There are two kinds of programmers in the world: those who expect floating values to behave like idealized Real numbers, and those whose programs using floating values actually work. In fact, among those whose programs work, C++ floats and operators that apply to them *do* implement what people expect from arithmetic operators. The only way they could get more predictable for these people would be to mandate that they be ieee standard floats (which do include NaN, FWIW). C++ floating types fit solidly into a long tradition of floating point numbers as supported in many other languages. I just want to close by saying that the domain of floating point isn't really amenable to glib pronouncements about what is "broken." If you need more evidence of that, read http://docs.sun.com/source/806-3568/ncg_goldberg.html -- Dave Abrahams Boost Consulting www.boost-consulting.com