|
Boost : |
From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-08-02 09:11:20
| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]] On Behalf Of Johan Råde
| Sent: 25 July 2006 11:32
| To: boost_at_[hidden]
| Subject: Re: [boost] is_nan
|
| 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).
I'd point out that one can (should?) use a separate test for the signbit,
using the C99 function signbit (which also works OK on zero and NaNs)
It would perhaps be more nicely named "is_negative" for C++.
But perhaps one would not wish to add yet another new name?
This sign bit exists on all types (or can simply return false if really is
unsigned),
even thouhg its meaning for zero and NaN is mathematically unclear.
Paul
--- Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539561830 & SMS, Mobile +44 7714 330204 & SMS pbristow_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk