Path: utzoo!attcan!uunet!husc6!uwvax!oddjob!uxc!uxc.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald From: mcdonald@uxe.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: Floating point puzzle Message-ID: <225800048@uxe.cso.uiuc.edu> Date: 7 Aug 88 13:13:00 GMT References: <3117@emory.uucp> Lines: 34 Nf-ID: #R:emory.uucp:3117:uxe.cso.uiuc.edu:225800048:000:710 Nf-From: uxe.cso.uiuc.edu!mcdonald Aug 7 08:13:00 1988 I tried running the following program on my IBM PC, using Microsoft C 5.1 with command line switch /Od - no optimization. #include main() { union { float fl; unsigned long lo; } x,y; x.fl = 1.0/10.0; y.fl = 1677721.0/16777216.0; printf("x: %lx", x.lo); printf("%20.17f\n",x.fl); printf("y: %lx", y.lo); printf("%20.17f\n",y.fl); } /* output is: x: 3dcccccd 0.10000000149011610 y: 3dccccc8 0.09999996423721313 /* Which is exactly what I would expect. The first one is 0.1 to almost 8 places, while the second is a bit smaller - just as it should be. Try running this program, or, if your compiler has 32bit ints, substitute "int" for "long" and "%x" for %lx". Doug McDonald