Skip to content

Instantly share code, notes, and snippets.

@jepler
Created June 6, 2017 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jepler/d2498a4feeabdcc46db5e9b552a76cd5 to your computer and use it in GitHub Desktop.
Save jepler/d2498a4feeabdcc46db5e9b552a76cd5 to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <stdio.h>
int main() {
double from = (1LL << 52), to = from + 2;
long long bucket[3] = { 0 };
int i;
for (i = 0; i < 1000000; i++) {
double r = from + (to - from) * (i / 1000000.);
unsigned int b = (int)(r - from);
assert(b < 3);
bucket[b]++;
}
for(i = 0; i < 3; i++ ) {
printf("%lld\n", bucket[i]);
}
return 0;
}
$ g++ roundish.cc && ./a.out
250001
499999
250000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment