Skip to content

Instantly share code, notes, and snippets.

@pandax381
Created August 17, 2017 02:48
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 pandax381/2bce5b76e44a6221a076c123d6115c53 to your computer and use it in GitHub Desktop.
Save pandax381/2bce5b76e44a6221a076c123d6115c53 to your computer and use it in GitHub Desktop.
simple float test
#include <stdio.h>
#include <stdint.h>
int
main (void) {
float a = 1.0;
float b = 2.0;
float c = a + b;
fprintf(stderr, "sizeof(float): %d\n", sizeof(float));
fprintf(stderr, "0x%x (%f) + 0x%x (%f) = 0x%x (%f)\n",
*(uint32_t *)&a, a,
*(uint32_t *)&b, b,
*(uint32_t *)&c, c
);
return 0;
}
@pandax381
Copy link
Author

$ ./float_test
sizeof(float): 4
0x3f800000 (1.000000) + 0x40000000 (2.000000) = 0x40400000 (3.000000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment