From: Maurice Lombardi Newsgroups: comp.os.msdos.djgpp Subject: Re: Another silly question about the double 0.1 ... Date: Wed, 17 Jun 1998 20:13:21 -0700 Organization: Universite Joseph Fourier - Grenoble 1, Grenoble, France Lines: 27 Message-ID: <358885D1.23EC95AB@ujf-grenoble.fr> References: <3587fb67 DOT 19298603 AT news DOT polimi DOT it> NNTP-Posting-Host: knautie.ujf-grenoble.fr Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Roberto Sassi a écrit: > #include > > int main(void) { > > double r=0.1; > double inc=0.05; > > for(;r<=0.25;r+=inc) > printf("%6.5f\n",r); > > } > better write: for (;r<=0.25001;r+=inc) it is fool to rely on exact roundings to end a loop. -- Maurice Lombardi Laboratoire de Spectrometrie Physique, Universite Joseph Fourier de Grenoble, BP87 38402 Saint Martin d'Heres Cedex FRANCE Tel: 33 (0)4 76 51 47 51 Fax: 33 (0)4 76 51 45 44 mailto:Maurice DOT Lombardi AT ujf-grenoble DOT fr