Skip to content

Instantly share code, notes, and snippets.

@you-ssk
Created July 16, 2016 09:04
Show Gist options
  • Save you-ssk/9188fd1db17cd86da80de3fd043f6351 to your computer and use it in GitHub Desktop.
Save you-ssk/9188fd1db17cd86da80de3fd043f6351 to your computer and use it in GitHub Desktop.
void f() {
/* sign 1 bit*/
/* exp 8 bit*/
/* frac = 23 bit*/
int binfloat[] = {
/* seeeeeeeefffffffffffffffffffffff */
0b00111111100000000000000000000000, /* 1.0 */
0b00111111110000000000000000000000, /* 1.5 */
0b00111111101000000000000000000000, /* 1.25 */
0b00111111100100000000000000000000, /* 1.125 */
0b00111111100010000000000000000000, /* 1.0625 */
0b00111111100001000000000000000000, /* 1.03125 */
0b00111111100000100000000000000000, /* 1.015625 */
0b00111111100000010000000000000000, /* 1.0078125 */
0b00111111100000001000000000000000, /* 1.00390625 */
0b00111111100000000100000000000000, /* 1.001953125 */
0b00111111100000000001000000000000, /* 1.00048828125 */
0b00111111100000000000010000000000, /* 1.0001220703125 */
0b00111111100000000000000100000000, /* 1.000030517578125 */
0b00111111100000000000000001000000, /* 1.00000762939453125 */
0b00111111100000000000000000010000, /* 1.0000019073486328125 */
0b00111111100000000000000000000100, /* 1.000000476837158203125 */
0b00111111100000000000000000000001, /* 1.000000011920928955078125 */
0b01000000000000000000000000000000, /* 2.0 */
0b01000000100000000000000000000000, /* 4.0 */
0b01000001000000000000000000000000, /* 8.0 */
0b01000001100000000000000000000000, /* 16.0 */
0b01000010000000000000000000000000, /* 32.0 */
0b01000010100000000000000000000000, /* 64.0 */
};
for (int i = 0; i < _countof(binfloat); i++) {
float* f = (float*)&binfloat[i];
printf("%.23f\t%a\t%08x\n", *f, *f, binfloat[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment