Created
August 31, 2017 23:38
-
-
Save jepler/0ebbd97520ef0c277577226f5180ba75 to your computer and use it in GitHub Desktop.
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 <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <inttypes.h> | |
int main() { | |
for(int i=0; i<1000000; i++) { | |
char s[16]; | |
snprintf(s, sizeof(s), "1.%06d", i); | |
double d = strtod(s, NULL); | |
uint64_t dc = (uint64_t)(d * 1e6); | |
if(dc != i + 1000000) | |
printf("%s %7" PRId64 " %.14A %.14A\n", s, dc, d, d*1e6); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This program shows all values of the form "1.xxxxxx" which, when multiplied by 1e6 and truncated to an integer don't equal the value you expect in decimal arithmetic.
On an x86_64 platform, counting the number of "unexpected" values:
On an armhf platform, the count is: