[kaffe] Re: The problem of "Double.c and buggy strtod" is settled
Dalibor Topic
robilad at yahoo.com
Thu Jun 5 10:37:02 PDT 2003
Hi Ito,
--- Dalibor Topic <robilad at yahoo.com> wrote:
>
> --- Ito Kazumitsu <kaz at maczuka.gcd.org> wrote:
> > >>>>> "*" == Ito Kazumitsu <kaz at maczuka.gcd.org> writes:
> >
> > *> In fact, FreeBSD 4.7-RELEASE's /usr/include/float.h says
> > *> #define DBL_MIN 2.2250738585072014E-308
> > *> and replace/strtod.c says, when HAVE_FLOAT_H is undefined,
> > *> almost the same thing:
> > *> # define DBL_MIN 2.2250738585072010e-308
> > *> I remember Linux 2.0.x's float.h also defines something like this.
> > *>
> > *> So Java's double MIN_VALUE 4.9406564584124654418e-324 will be
> > *> considered to be 0.0 by this strtod.c.
> >
> > Studying this issue further, I found that DBL_MIN is not the only
> > factor that makes strtod convert 4.9406564584124654418e-324 to 0.0.
> >
> > Even if I comment out
> > if (num < DBL_MIN * pow (10.0, (double) -exponent))
> > goto underflow;
> > this strtod converts 4.9406564584124654418e-324 to 0.0 although
> > errno is not set.
> >
> > Inserting "printf("## num, exp = %f, %d\n", num, exponent);"
> > before "num *= pow (10.0, (double) exponent);", I get
> > "## num, exp = 49406564584124661760.000000, -343". So
> > the reason why 4.9406564584124654418e-324 becomes 0.0
> > seems to be the limitation of the function pow().
>
> o.k., since the strtod from libit doesn't work, the one from libiberty (gcc)
> doesn't work either, I'll see if I can get the one from NetBSD to work, since
> you've had some success with it.
the netbsd strtod seems to need some includes that I don't have around, and the
netlib strtod wants me to specify way more about IEEE than I know ;) The one
from glibc is entangles in the glibc mess of headers, so I took another look at
the one from libiberty. I hope that the attached patch works, I've tried a
slightly adapted DoubleTest.c and it worked for me:
bash-2.05a$ gcc -g DoubleTest.c libiberty-strtod.c safe-ctype.c -I .
bash-2.05a$ ./a.out 4.9406564584124654418e-324
4.9406564584124654418e-324 0 4.94065645841246544177e-324
bash-2.05a$ cat DoubleTest.c
#include <stdlib.h>
extern int errno;
int main(int argc, char* argv[]) {
double d = strtod(argv[1], NULL);
printf("%s %d %40.20e\n",argv[1], errno, d);
}
cheers,
dalibor topic
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dalibor-strtod-2-newfiles.tgz
Type: application/x-tar-gz
Size: 4540 bytes
Desc: dalibor-strtod-2-newfiles.tgz
Url : http://kaffe.org/pipermail/kaffe/attachments/20030605/14f45143/attachment-0004.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dalibor-strtod-2.diff.gz
Type: application/gzip
Size: 7156 bytes
Desc: dalibor-strtod-2.diff.gz
Url : http://kaffe.org/pipermail/kaffe/attachments/20030605/14f45143/attachment-0005.bin
More information about the kaffe
mailing list