Boost logo

Boost :

From: Paul Giaccone (paulg_at_[hidden])
Date: 2006-07-25 06:23:50


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk