template <class T>
MyClass
{
public:
// ...
void MyMethod(T dbNumber)
{
// ...
T dbResult = do_some_operation_on_dbnumber(dbNumber);
if (IsInfinite(dbResult))
{
// ...
}
else if (IsIndefinite(dbResult))
{
// ...
}
else
{
// ...
}
// ...
}
static bool IsInfinite(T dbNumber)
{
// How do I implement this?
}
static bool IsIndefinite(T dbNumber)
{
// How do I implement this?
}
// ...
};
There is a mathematical operation in my code which sometimes return infinite and indefinite results in a template variable. I want to catch these kind of indefinite results. How do I do that?
#include <limits>
using namespace std;
double d = 1.0 / 0.0;
if (d == numeric_limits<double>::infinity( ))
cout << "Its infinite, all right" << endl;
else
cout << "Not in my book" << endl;
This works.