How about testing if x - (int)x == 0.0 .

Quote Originally Posted by Flying Mullet
Well you could always use a brute force approach.

1) Treat the input as a string.
2) Go through the input character by character and verify that each character is only 0-9 or a ".".
3) If there is a ".", check that there is only one ".".
4) If there is no decimal and it's a valid number then you have an integer.
5) If there is a decimal, see if there is any number other than zero following it.
6) If there are only zeros, then you have an integer, otherwise it's a float.

It's not as pretty but it would work.
I think it depends on the definition of "is an integer". If you input 1.0, to store it into an int variable it would have to be cast as an int from a float or double at some point. 1.0 is technically a floating point number, mathematically equal to 1 but maybe not computationally equal. Strictly speaking I wouldn't call 1.0 an integer.

Using your definition above though, 1e2 would also be an integer.

My C is more than a bit rusty (and spoiled from Perl) but I think you can enter integers in straight hexidecimal in C, such as 0x100. Or in binary, 0b1001.

You can also have + or - at the beginning of an integer.