Last active
January 23, 2023 13:59
-
-
Save zarmin/294cc7f05695bc1c2391fa231f2c30fd to your computer and use it in GitHub Desktop.
is double an integer
This file contains 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
#include <inttypes.h> | |
int isInteger(double input) { | |
uint64_t x = *((uint64_t*)&input); | |
if ((x & 0x7fffffffffffffffULL) == 0) | |
return 1; | |
int i; | |
for (i = 52; i >= 0 && !(x & (1ULL << (52-i))); i--); | |
return (int)(((x & 0x7ff0000000000000ULL) >> 52) - 1023) >= i; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment