1. Check to intiness

This is no doubt simple, but how can I check if a double contains an integral value?

2. Test against INT_MIN and INT_MAX or 0 and UINT_MAX in <climits>, or the equivalent templates from numeric_limits in <limits>. But beware testing for equality with floating-point, it's a pain to get right.

3. I've solved it: put the double's value into an int, then check equality of the original double with the new int typecasted as a double. If they are equal, then the original double is an integer. Gotta love truncation.

4. >put the double's value into an int
And what if the double's value is out of range for an int? Signed overflow is undefined.

5. You could also have a "imperfect" floating point value.

6. I didn't compile this, but...basically this just ensures the value is in the range of an int, casts it, and then restores it to the original magnitude. The pointers are there to save us from having to use two separate loops (one for greater, one for less than zero).

Code:
``` double integral(double n)
{
int f = 0;
double m, * l, * r;

if(n > 0)
{
m = INT_MAX;
l = &n, r = &m;
}
else
{
m = INT_MIN;
l = &m, r = &n;
}

while(*l > *r)
{
++f;
n -= m;
}

n = (int)n;

if(f)
{
n += f * m;
}

return n;
}

bool is_integral(double n)
{
return n-integral(n) == 0;
}```

7. Neat. Thanks.