Mail Archives: djgpp/1998/06/17/10:39:33
after modifying Your program as follows, You get the 'right' output, so
be aware of using direct comparisions between any floting types !!!
#include <stdio.h>
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
~
- Raw text -