double precision FP problem in Turbo C's strtod()
Robert G Kaires
kaires at hubcap.clemson.edu
Sun Mar 4 14:00:47 AEST 1990
I am using Turbo C 2.0. Double precision floating numbers are supposed
to have a range from 10e-308 to 10e+308. So why does the following
short program yield zero when 10e-100 is entered for "string". It
doesn't have a problem with 10e+100! Is this a bug? I also have the
same problem if I use the atof() function.
On a related question: does anyone have a list of known bugs in Turbo C
2.0 (and their fixes!).
Thanks for any and all help.
Bob Kaires
3/3/90
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main()
{
char string[30]={""};
char *ptr;
double ans;
clrscr();
while(1)
{
gets(string);
if (*string == 'q') break;
ans=strtod(string,&ptr);
if ( ( string+strlen(string) ) != ptr )
printf("format error\n");
else
printf("You typed the number: %E\n",ans);
}
}
More information about the Comp.lang.c
mailing list