Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!agate!shelby!rutgers!cbmvax!rsbx From: rsbx@cbmvax.commodore.com (Raymond S. Brand) Newsgroups: comp.sys.amiga Subject: Re: Lattice C double Message-ID: <14909@cbmvax.commodore.com> Date: 5 Oct 90 16:00:21 GMT References: <1990Sep28.063045.2599@ericsson.se> <14795@cbmvax.commodore.com> <14905@cbmvax.commodore.com> Organization: Commodore-Amiga Inc, West Chester, PA Lines: 50 In article <14905@cbmvax.commodore.com>, ken@cbmvax.commodore.com (Ken Farinsky - CATS) writes: > In article <1990Oct4.063507.1899@ericsson.se> etxpnil@etxsj23.ericsson.se writes: > >In article <14795@cbmvax.commodore.com> ken@cbmvax.commodore.com writes: > >>In article <1990Sep28.063045.2599@ericsson.se> etxpnil@etxsj23.ericsson.se writes: > >>>main() > >>>{ > >>> double dub; > >>> dub = 12345678.0; > >>> dub = dub * 10.0; > >>> printf("%.9g\n",dub); > >>>} > >>>When compiled with the Lattice C V5.04, I've got the following output: > >>>123456779.999999999 > >> > >>Are you using the correct compiler flags and linker options... > > > >I've now tried it...with the same result... > > Nope, that doesn't do it. Looks like the problem is that you are > displaying more than 15 digits, which is beyond the accuracy of > the numeric format that you are using. If you use a smaller > number (1234.0), then you get the result that you expect. Are the > other machines that you are using this on using a different > numeric format? > -- > Ken Farinsky - CATS - (215) 431-9421 - Commodore Business Machines The problem is in printf. The binary result of the mult is exact. For some interesting reading on the problems and some solutions to the problems of translating floating-point numbers between different bases, read the two papers from the ACM SIGPLAN'90 conference proceedings: "How to Read Floating Point Numbers Accurately" William D Clinger, University or Oregon Pages 92-101 "How to Print Floating-Point Numbers Accurately" Guy L Steele Jr., Thinking Machines Corporation Jon L White, Lucid, Inc. Pages 112-126 rsbx ------------------------------------------------------------------------ Raymond S. Brand rsbx@cbmvax.commodore.com Commodore-Amiga Engineering ...!uunet!cbmvax!rsbx 1200 Wilson Drive (215)-431-9100 West Chester PA 19380 "Looking" ------------------------------------------------------------------------