Skip to content

Instantly share code, notes, and snippets.

@Gaurav-Singh-97
Created December 2, 2016 17:13
Show Gist options
  • Save Gaurav-Singh-97/02bc249dd1ed3d785e666a24727facf4 to your computer and use it in GitHub Desktop.
Save Gaurav-Singh-97/02bc249dd1ed3d785e666a24727facf4 to your computer and use it in GitHub Desktop.
Self implemented IsInteger() function in C++
#ifndef IsInteger
#define IsInteger
// Note: Here, RealNumberType should be convertible to int
// and the value contained in RealNumberType should not be greater than
// max value of int
//Maybe IntegerType should only be take as template arguement (seems necessary)
//Original type of arguement might be found using typeinfo or something...(Not sure, check)
namespace GS{
template <typename RealNumberType>
bool isInteger(RealNumberType n)
{
int i = (int)n;
return ((RealNumberType)i==n);
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment