Skip to content

Instantly share code, notes, and snippets.

@zarmin
Last active January 23, 2023 13:59
Show Gist options
  • Save zarmin/294cc7f05695bc1c2391fa231f2c30fd to your computer and use it in GitHub Desktop.
Save zarmin/294cc7f05695bc1c2391fa231f2c30fd to your computer and use it in GitHub Desktop.
is double an integer
#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