Path: utzoo!utgpu!water!watmath!clyde!motown!vilya!lcuxlm!whuts!att!rutgers!gatech!mcnc!thorin!unc!barkley From: barkley@unc.cs.unc.edu (Matthew Barkley) Newsgroups: comp.lang.c Subject: New floating point puzzle Keywords: Floating point, printf Message-ID: <3863@thorin.cs.unc.edu> Date: 18 Aug 88 02:13:13 GMT Sender: news@thorin.cs.unc.edu Lines: 34 In trying out the problem program from the "floating point puzzle" posting, I came across some strange behavior in trying to make the program more con- cise. Here's what I ran and what I got: /* Puzzling floating-point program */ main() { float x,y; x = 1.0/10.0; y = 1677721.0/16777216.0; printf("x: %x",x); printf("%20.17f\n",x); printf("y: %x",y); printf("%20.17f\n",y); printf("\n"); printf("x: %x %20.17f\n",x,x); printf("y: %x %20.17f\n",y,y); } /* Here is the output: (from VAX 11/780) */ /* x: cccd3ecc 0.10000000149011612 */ /* y: ccc83ecc 0.09999996423721313 */ /* x: cccd3ecc 0.00000000000000000 */ /* y: ccc83ecc 0.00000000000000000 */ So, please gurus, tell me where the bug (if any) is. Is it unreasonable to expect the 2 sets of output to be the same? (BTW, the results are more bizarre if x and y are of type double.) Matt Barkley barkley@unc.cs.unc.edu Any opinions expressed are not necessarily shared by anyone else, and may not even be my own. How an organization can have an opinion is beyond me.