Sender: hecht AT DH_NRZ24 DOT dillinger DOT de Message-ID: <3587C720.794B@dillinger.de> Date: Wed, 17 Jun 1998 16:39:44 +0300 From: michael hecht MIME-Version: 1.0 To: sassi AT biomed DOT polimi DOT it CC: djgpp AT delorie DOT com Subject: Re: A question about atof() and the double 0.1 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk after modifying Your program as follows, You get the 'right' output, so be aware of using direct comparisions between any floting types !!! #include int main(void) { char rr[10]; long double r=0.0; long double inc=(long double)0.05; rr[0]='0'; rr[1]='.'; rr[2]='1'; rr[3]='\0'; r= (long double) strtold(rr,NULL); if(r==((long double)0.1)) printf("OKAY\n"); else printf("ERROR\n"); printf("%40.38lf\n",(double)r); r+=inc; if(r<=(long double)0.15) printf("OKAY\n"); else printf("ERROR\n"); if(r==(long double)0.15) printf("OKAY\n"); else printf("ERROR\n"); rr[0]='0'; rr[1]='.'; rr[2]='1'; /* only a test */ rr[3]='5'; rr[4]='\0'; r= (long double) strtold(rr,NULL); if(r==((long double)0.15)) printf("OKAY\n"); else printf("ERROR\n"); printf("%40.38lf\n",(double)r); } ERROR 0.10000000000000001000000000000000000000 ERROR ERROR ERROR 0.14999999999999999000000000000000000000 ~