Skip to content

Instantly share code, notes, and snippets.

@Plutor
Created August 13, 2013 14:29
Show Gist options
  • Save Plutor/6221648 to your computer and use it in GitHub Desktop.
Save Plutor/6221648 to your computer and use it in GitHub Desktop.
A demonstration of the inaccuracy of storing large numbers in floating point.
#include <stdio.h>
int main() {
printf("1111111111111111 = %.0f\n", 1111111111111111.0);
printf("11111111111111111 = %.0f\n", 11111111111111111.0);
printf("111111111111111111 = %.0f\n", 111111111111111111.0);
printf("1111111111111111111 = %.0f\n", 1111111111111111111.0);
printf("11111111111111111111 = %.0f\n", 11111111111111111111.0);
printf("111111111111111111111 = %.0f\n", 111111111111111111111.0);
return 0;
}
/* Output:
1111111111111111 = 1111111111111111
11111111111111111 = 11111111111111112
111111111111111111 = 111111111111111104
1111111111111111111 = 1111111111111111168
11111111111111111111 = 11111111111111110656
111111111111111111111 = 111111111111111114752
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment