Skip to content

Instantly share code, notes, and snippets.

@zhuowei
Created January 27, 2019 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhuowei/020e619569a980b5f53d34a572371509 to your computer and use it in GitHub Desktop.
Save zhuowei/020e619569a980b5f53d34a572371509 to your computer and use it in GitHub Desktop.
#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);
}
$ 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