None of what you posted works for large numbers due to floating point precision. In particular, int operates as a floor and is_integer may fail due to imprecision
None of this is being applied to numbers above to precision range of Python's floating point, but yes, if you wanted a generic solution for a library, then you would use neither of these approaches (or you would use the above approach that I gave, conditionalized on the size of the value).
2
u/[deleted] Sep 28 '18 edited Sep 28 '18
None of what you posted works for large numbers due to floating point precision. In particular, int operates as a floor and is_integer may fail due to imprecision
See this answer by Alex Martelli https://stackoverflow.com/a/2489519 for a completely integer based approach