
Paul Giaccone wrote:
Johan Råde wrote:
Floating point numbers can be classified into four categories:
1. finite numbers 2. infinity 3. negative infinity 4. not-a-number (nan)
So maybe we need functions:
[snip] template<class T> bool is_infinity(T a) { return std::numeric_limits<T>::has_infinity && a == std::numeric_limits<T>::infinity(); }
[snip]
You test for negative infinity by calling is_infinity(-a).
....for which it would be easy enough to provide a convenience function (perhaps "is_minus_infinity"), which would just be a wrapper around "is_infinity".
Another useful convenience function would be "is_infinite", which would return true if and only if the number was equal to plus or minus infinity (making use of either "is_finite" or both "is_infinity" and "is_minus_infinity")
The similarity of the names of "is_infinity" and "is_infinite" might be a problem, but the former could be changed to "is_plus_infinity" to give symmetry with "is_minus_infinity".
Paul
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
I agree that having the three functions is_infinite (or maybe is_infinity) is_plus_infinity is negative_infinity is a good idea. John's proposal has the function is_infinity, in the sense of both plus and minus infinity, but not the functions is_plus_infinity and is_negative_infinity. Maybe John's intention is that one should test for plus infinity by writing is_infinity(x) && x >= 0 That would work, but is probably inefficient. --Johan