Created
June 6, 2017 22:52
-
-
Save jepler/d2498a4feeabdcc46db5e9b552a76cd5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <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; | |
} |
This file contains hidden or 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
$ 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