X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=dump-float.c;h=7f5b7c880fa385e221542aa725b915f5264fafd4;hb=825c6bde8038dcb024a25b89a3591fbc21b25d1d;hp=84e4115e1915e7e8663241f54640d382c1efb769;hpb=2618ed943daf22c2b46f6dd76b7700739c5afb84;p=pspp diff --git a/dump-float.c b/dump-float.c index 84e4115e19..7f5b7c880f 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 = { 0x18, 0x00, 0x00, 0x1c, 0xf0, 0xff, 0xff, 0x5f } }; - printf ("%f\n", x.d); + uint8_t b[] = { 0, 0, 0, 0, 0, 0, 8, 0x40 }; + 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; }