The trivial solution would be:
class Number
{
public:
bool isFinite();
bool isPositive();
double value();
...
private:
double value_;
bool isFinite_;
bool isPositive_;
...
};
The thing that worries me is efficiency:
From Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition) by Scott Meyers:
Even when small objects have inexpensive copy constructors, there can
be performance issues. Some compilers treat built-in and user-defined
types differently, even if they have the same underlying
representation. For example, some compilers refuse to put objects
consisting of only a double into a register, even though they happily
place naked doubles there on a regular basis. When that kind of thing
happens, you can be better off passing such objects by reference,
because compilers will certainly put pointers (the implementation of
references) into registers.
Is there a way to bypass the efficiency problem? For example a library that uses some assembly language magic?
There is very little reason to implement a Number class for a double. The double format already implement Infinity, NaN, and signage as part of the raw basic double type.
Second, you should write your code first aiming for correctness, and then try to optimize later, at which time you can look at factor out specific data structure and rewrite code and algos.
Modern day compilers are typically very efficient in writing good code, and typically does a way better job than most human programmers does.