Skip to content

Instantly share code, notes, and snippets.

@mskashi
Created March 1, 2016 09:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mskashi/bd59f51d934d3c7ed42c to your computer and use it in GitHub Desktop.
Save mskashi/bd59f51d934d3c7ed42c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <float.h>
#include <stdint.h>
#include <inttypes.h>
int64_t d2i(double x)
{
union {
int64_t i;
double d;
} tmp;
tmp.d = x;
if (tmp.i < 0) {
tmp.d = -x;
return -tmp.i;
} else {
return tmp.i;
}
}
int main()
{
printf("%" PRId64 "\n", d2i(1 + DBL_EPSILON) - d2i(1.));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment