Last active
January 11, 2017 09:19
-
-
Save bast/e9cc08bcfdebcf17957765b91e775fdf to your computer and use it in GitHub Desktop.
Example demonstrating increment problem with 32-bit float.
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 "stdio.h" | |
/* example obtained from Ole Martin Bjoerndalen */ | |
int main() | |
{ | |
float a = 16777216; | |
printf("before increment %f\n", a); | |
float b = a + 1; | |
printf("after increment by one %f\n", b); | |
/* the integer part of a 32-bit float is 24 bits, if you add 2 you get the correct result */ | |
b = a + 2; | |
printf("after increment by two %f\n", b); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment