X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dump-float.c;h=21aa391d068cc319a863100348a0b01f9cf53782;hb=6ca1cdb717c55f8a4b4567285e9b44a8822504c9;hp=9e2d4bef319a4a3aa11c1475ab9ee29cb00e12a2;hpb=8b7ea7f744c5e82874cd28cb36c44a2d99e5894b;p=pspp diff --git a/dump-float.c b/dump-float.c index 9e2d4bef31..21aa391d06 100644 --- a/dump-float.c +++ b/dump-float.c @@ -1,15 +1,33 @@ #include #include +#include + +void +print_double (const uint8_t *b) +{ + double d; + memcpy (&d, b, 8); + printf ("%f\n", d); +} + +void +print_float (const uint8_t *b) +{ + float d; + memcpy (&d, b, 4); + printf ("%f\n", d); +} int main (void) { - union - { - uint8_t b[8]; - double d; - } - x = { .b = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0xdd, 0x40 } }; - printf ("%f\n", x.d); + uint8_t b[] = { 0x1f, 0x05, 0, 0, 0xa2, 3, 0, 0, 0x64, 0, 0, 0 }; + int n = sizeof b; + for (int i = 0; i <= n - 8; i++) + print_double (b + i); +/* + for (int i = 0; i <= n - 4; i++) + print_float (b + i); +*/ return 0; }