Created
December 2, 2016 17:13
-
-
Save Gaurav-Singh-97/02bc249dd1ed3d785e666a24727facf4 to your computer and use it in GitHub Desktop.
Self implemented IsInteger() function in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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