Created
January 27, 2019 02:47
-
-
Save zhuowei/020e619569a980b5f53d34a572371509 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 <stdio.h> | |
int main() { | |
union { | |
unsigned int a; | |
float b; | |
} theunion; | |
theunion.a = (0x80 << 23) | 0x7fffff; | |
printf("%x %.30f\n", theunion.a, theunion.b); | |
theunion.a += 1; | |
printf("%x %.30f\n", theunion.a, theunion.b); | |
} |
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
$ clang nextfloat.c | |
$ ./a.out | |
407fffff 3.999999761581420898437500000000 | |
40800000 4.000000000000000000000000000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment